05.02.2020, 07:31
Log what you get during login request. I've also changed data variable to contain valid JSON:
Code:
require('json')
http = require('socket.http')
http.TIMEOUT = 5
data = json.encode({
username = 'user',
password = '12345'
})
url1 = 'https://10.10.11.2:8443/api/login'
url2 = 'https://10.10.11.2:8443/api/s/default/stat/sta'
res, err, hdrs = http.request(url1, data)
log(res, err, hdrs)
if res then
tbl = {}
res, err = http.request({
url = url2,
headers = {
cookie = hdrs['set-cookie']
},
sink = ltn12.sink.table(tbl),
})
if res then
resp = table.concat(tbl)
log(resp)
else
alert('request 2 failed: ' .. tostring(err))
end
else
alert('request 1 failed: ' .. tostring(err))
end