Created
November 16, 2015 04:21
-
-
Save ivan-loh/f14b9ae1f17646a9a81b to your computer and use it in GitHub Desktop.
sample lua http get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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