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.

Twinkly script
#5
(07.12.2020, 11:14)admin Wrote: 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

yes, thanks
Reply


Messages In This Thread
Twinkly script - by gjniewenhuijse - 07.12.2020, 09:12
RE: Twinkly script - by admin - 07.12.2020, 10:02
RE: Twinkly script - by gjniewenhuijse - 07.12.2020, 10:21
RE: Twinkly script - by admin - 07.12.2020, 11:14
RE: Twinkly script - by gjniewenhuijse - 07.12.2020, 12:02
RE: Twinkly script - by gjniewenhuijse - 07.12.2020, 19:50

Forum Jump: