Skip to content

Instantly share code, notes, and snippets.

@ivan-loh
Created November 16, 2015 04:21
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ivan-loh/f14b9ae1f17646a9a81b to your computer and use it in GitHub Desktop.
Save ivan-loh/f14b9ae1f17646a9a81b to your computer and use it in GitHub Desktop.
sample lua http get
local http = require "socket.http"
local data = ""
local function collect(chunk)
if chunk ~= nil then
data = data .. chunk
end
return true
end
local ok, statusCode, headers, statusText = http.request {
method = "GET",
url = "http://someserver.sometld/somepath",
sink = collect
}
print("ok\t", ok);
print("statusCode", statusCode)
print("statusText", statusText)
print("headers:")
for i,v in pairs(headers) do
print("\t",i, v)
end
print("data", data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment