Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
how get response header? — Gideros Forum

how get response header?

duke2017duke2017 Member
edited June 2014 in General questions
loader:addEventListener(Event.COMPLETE, function(event)
body = event.data
end)

In event.data contains body, but how can I get header? (I need to get the cookie contained in header)
thanks

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @duke2017 unfortunately can't do it with UrlLoader, but can do it with LuaSocket:
    local query = "key1=value1&key2=value2"
    local response = {} 
    local res, code, headers, status = http.request {
        method = "POST",
        url = "<a href="https://yourwebsite.com/"" rel="nofollow">https://yourwebsite.com/"</a>,
        source = ltn12.source.string(query),
        headers = 
            {
                   ["Accept"] = "*/*",
                   ["Accept-Encoding"] = "gzip, deflate",
                   ["Accept-Language"] = "en-us",
                   ["Content-Type"] = "application/x-www-form-urlencoded",
                   ["content-length"] = string.len(query)
            },
        sink = ltn12.sink.table(response)
    }
     
    print('body:' .. table.concat(response))
    print('code:' .. tostring(code))
    print('headers:' .. table.concat(headers))
    print('status:' .. tostring(status))
    result:
    body:1
    code:200
    headers:  "set-cookie": "config_version=887; expires=Sat, 29-Jun-2013 19:07:09 GMT; Max-Age=86400; Path=/"
      "date": "Fri, 28 Jun 2013 19:07:09 GMT"
      "ed-config-version": "887"
      "content-encoding": "gzip"
      "cache-control": "private, no-cache, no-store, must-revalidate"
      "connection": "Close"
      "vary": "Cookie"
      "content-length": "52"
      "pragma": "no-cache"
      "content-type": "application/json; charset=utf-8"
      "server": "nginx/1.2.7"
     
    status:HTTP/1.1 200 OK

    Likes: duke2017

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.