Sample Script: TLuaHTTPClient
--Script to download a html page from a web server
http = TLuaHTTPClient()
--Connect using the default parameters
iRet = http:Connect()
if iRet ~= 0 then
--Make a GET request to default document
iRet = http:Get("/")
--Print returned code from HTTP server
print("Code:"..iRet)
--Extract content length
iRet = http:GetHeaderContentLength()
print("Content length:"..iRet)
--Print content
string,iRet = http:GetContent(iRet)
print(string)
--Print raw headers
string = http:GetHeadersRaw()
print("headers:\n"..string)
--Print cookies
string = http:GetHeaderCookies()
print("Cookies:\n"..string)
--Extract and print cookies one by one
iNumber = http:GetHeaderCookieCount()
for count = 0, iNumber-1 do
string = http:GetHeaderCookie(count)
print("Cookie #"..count.." "..string.."\n")
end
--Extract location header
string = http:GetHeaderLocation();
print("location:\n"..string)
SetExitStatus("Test ok",true)
else
print("Connect failed")
SetExitStatus("Test failed",false)
end