httprequest

Performs HTTP connections.

Methods

clearresponse()

Clears the HTTP response data

getheader(field)

Gets the value of a field or (if no field is provided) the full response header
returns: string
> = http:getheader('Server')
Apache
> = http:getheader()
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.3.7 (Unix)  (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Etag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text/html; charset=UTF-8'

getresponse(returntype)

Gets the response (return type can be: text, base64 or filename. If no return type is provided, returns the response text)
returns: string

open(method,url)

Performs a request

--example 1
http:open('GET','http://www.lua.org/')
--example 2
http.postdata = 'param=val&param2=val2'
http:open('POST','http://www.lua.org/')

openlow(host,port,headers)

Sends a custom HTTP request with custom headers

--example
hdr = [[GET / HTTP/1.1
Connection: Keep-Alive]]
http:openlow('www.lua.org',80,hdr.."\n\n")

getrequestheader(field)

Gets the value of a field or (if no field is provided) the full request header
returns: string

Methods (Proxy)

setproxy(table)

Sets a proxy

--example
http:setproxy{
 server = '127.0.0.1',
 port = 8080,
 username = 'admin',
 password = 'test'
}

setsocks(table)

Sets a socks server

--example
http:setsocks{
 server = 'somehost',
 port = 1080,
 username = 'admin',
 password = 'test',
 level = '5'
}

Properties (Response)

contentlengthintegerGets the content length
errorintegerGets the error code (0 means no error)
errordescstringGets the error description
requestinfojsonReturns a JSON string with request and response details
statusintegerGets the status code
textstringGets the response text

Properties (Request)

agentstringGets or sets a custom user agent
autolengthbooleanEnables auto content-lenth generation (for POST requests)
connectionstringGets or sets the Connection type (Close, Keep-Alive)
cookiestringGets or sets a cookie
descriptionstringGets or sets a description for the request (This is returned as part of the JSON string from the requestinfo property)
enablegzipbooleanEnables or disables GZIP compression
maxretryintegerGets or sets the max number of retries (0 for disabled)
postdatastringGets or sets the POST data to be used in a POST request
timeoutintegerGets or sets a timeout value (in ms)
useproxybooleanEnables or disables proxy usage
versionstringGets or sets the HTTP version (1.0 or 1.1)

Properties (Authentication)

authstringGets or sets the type of server authentication (None, Basic, NTLM)
usernamestringGets or sets an username for server authentication
passwordstringGets or sets a password for server authentication

Usage Example


http = scl.httprequest:new()
http:open('GET','http://www.lua.org/')
print(http.text)
http:release()