07.10.2022, 08:31
Try this:
Code:
require('socket.http')
require('ltn12')
require('json')
email = "username@email.com"
password = "password_here"
powerstation_id = "Portal_ID_here"
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
body = encodepost({
account = email,
pwd = password,
code = "",
})
headers = {
["sec-ch-ua"] = "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"99\", \"Microsoft Edge\";v=\"99\"",
["Accept"] = "application/json, text/javascript, */*; q=0.01",
["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8",
["X-Requested-With"] = "XMLHttpRequest",
["sec-ch-ua-mobile"] = "?0",
["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39",
["sec-ch-ua-platform"] = "\"Windows\"",
["Origin"] = "https://eu.semsportal.com",
["Sec-Fetch-Site"] = "same-origin",
["Sec-Fetch-Mode"] = "cors",
["Sec-Fetch-Dest"] = "empty",
["Referer"] = "https://eu.semsportal.com/home/login",
["Accept-Language"] = "en-GB,en;q=0.9,en-US;q=0.8",
["Content-Length"] = #body,
}
response = {}
res, code, hdrs, stat = socket.http.request({
url = "https://eu.semsportal.com/Home/Login",
method = "POST",
headers = headers,
source = ltn12.source.string(body),
sink = ltn12.sink.table(response),
})
cookie = hdrs['set-cookie']
if cookie then
headers["Cookie"] = cookie:split(';')[1]
end
headers["Referer"] = "https://eu.semsportal.com/PowerStation/PowerStatusSnMin/" .. powerstation_id
log(res, code, hdrs, stat, response)
body = encodepost({
str = json.encode({
api = "v1/PowerStation/GetMonitorDetailByPowerstationId",
param = {
powerStationId = powerstation_id
}
})
})
response = {}
res, code, hdrs, stat = socket.http.request({
url = "https://eu.semsportal.com/GopsApi/Post?s=v1/PowerStation/GetMonitorDetailByPowerstationId",
method = "POST",
headers = headers,
source = ltn12.source.string(body),
sink = ltn12.sink.table(response),
})
log(res, code, hdrs, stat, response)