07.09.2020, 09:17
Login part in your example was incorrect. POST data must be encoded correctly.
Code:
user = 'user@example.com'
pass = 'password'
poolid = '123456'
http = require('socket.http')
ltn12 = require('ltn12')
json = require('json')
resp = {}
url1 = 'http://www.vistapool.es/en/login/login'
url2 = 'http://www.vistapool.es/en/pool/getmainvalues?id=' .. poolid
function encodepost(t)
local res = {}
local esc = require('socket.url').escape
for k, v in pairs(t) do
res[ #res + 1 ] = esc(k) .. '=' .. esc(v)
end
return table.concat(res, '&')
end
data = encodepost({
user = user,
pass = pass,
remember_password = '0',
entrar = 'Enter'
})
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)
data = json.pdecode(resp)
log(data)
else
alert('request 2 failed: ' .. tostring(err))
end
else
alert('request 1 failed: ' .. tostring(err))
end