Logic Machine Forum
Help me ! - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Help me ! (/showthread.php?tid=1062)



Help me ! - phongvucba - 26.10.2017

-------------------
http = require('socket.http')
require('socket.http')

local anh = http.request {
  url = "api.speedsms.vn/index.php/user/info",
  headers = { authentication = "Basic " .. (mime.b64("kuDkYXtIBidDjCRmN8z_Yt9U12Dbs8TZ:x")) }
  }
alert('value is:'..anh)
---------------------
It reported error value "he" is "a nil value"
Am I wrong in that? Any wrong structure? Please help me !
Thank so much everyone.  Heart


RE: Help me ! - admin - 26.10.2017

url must start with http://, also run your request like this so you can see full server response in Logs tab:
Code:
http = require('socket.http')
log(http.request {
  url = "api.speedsms.vn/index.php/user/info",
  headers = { authentication = "Basic " .. (mime.b64("kuDkYXtIBidDjCRmN8z_Yt9U12Dbs8TZ:x")) }
})



RE: Help me ! - phongvucba - 26.10.2017

Oh, thank so much admin !
If the value of his "anh" is Json, how to get that value "balance number" on alert or send sms to the user?
---------------
{ "status": "success", "code": "00", "data": { "email": "your email address", "balance": "balance number", "currency": "VND" } }
---------------
local anh = http.request {
  url = "http://api.speedsms.vn/index.php/user/info",
  headers = { Authorization = "Basic " .. (mime.b64("kuDkYXtIBidDjCRmN8z_Yt9U12Dbs8TZ:x")) }
}
--------------------
Thank admin with this help!


RE: Help me ! - phongvucba - 02.11.2017

Help me ! top top


RE: Help me ! - admin - 03.11.2017

Code:
require('json')
http = require('socket.http')
resp = {}
res = http.request({
  url = "http://api.speedsms.vn/index.php/user/info",
  headers = { authentication = "Basic " .. (mime.b64("kuDkYXtIBidDjCRmN8z_Yt9U12Dbs8TZ:x")) },
  sink = ltn12.sink.table(resp)
})
if res then
  resp = table.concat(resp)
  resp = json.pdecode(resp)
  if resp then
    log(resp.data.balance)
  end
end



RE: Help me ! - Erwin van der Zwart - 03.11.2017

Hi,

Should that not be log(resp.data.balance)?

BR,

Erwin


RE: Help me ! - admin - 03.11.2017

Yes, thanks Erwin!


RE: Help me ! - phongvucba - 04.11.2017

Thank so much admin and Erwin van der Zwart!
I was successful !
Smile