This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Vistapool Integration
#4
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
Reply


Messages In This Thread
Vistapool Integration - by joost001 - 07.09.2020, 06:56
RE: Vistapool Integration - by admin - 07.09.2020, 07:00
RE: Vistapool Integration - by joost001 - 07.09.2020, 08:37
RE: Vistapool Integration - by admin - 07.09.2020, 09:17
RE: Vistapool Integration - by joost001 - 09.09.2020, 10:00

Forum Jump: