07.12.2020, 11:14
You are missing the Content-Length header for the POST request. This should help:
Code:
function getTwinklyResponseData(endPoint, body, content_type)
local content_type = content_type or "application/json"
local url = "http://" .. host .. api.base .. api.endpoints[endPoint]
local method = "GET"
local cl
if body ~= nil then
method = "POST"
if type(body) == "table" and content_type == "application/json" then
body = json.encode(body)
end
cl = #body
end
local response_body = {}
local res, code, response_headers, status = socket.http.request({
url = url,
method = method,
headers =
{
["Content-Type"] = content_type,
["Content-Length"] = cl,
["X-Auth-Token"] = authToken
},
source = ltn12.source.string(body),
sink = ltn12.sink.table(response_body)
})
if res then
return code == 200
end
end