httprequest
Performs HTTP connections.
Methods
Clears the HTTP response data
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'
Gets the response (return type can be: text, base64 or filename. If no return type is provided, returns the response text)
returns: string
Performs a request
--example 1
http:open('GET','http://www.lua.org/')
--example 2
http.postdata = 'param=val¶m2=val2'
http:open('POST','http://www.lua.org/')
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")
Gets the value of a field or (if no field is provided) the full request header
returns: string
Methods (Proxy)
Sets a proxy
--example
http:setproxy{
server = '127.0.0.1',
port = 8080,
username = 'admin',
password = 'test'
}
Sets a socks server
--example
http:setsocks{
server = 'somehost',
port = 1080,
username = 'admin',
password = 'test',
level = '5'
}
Properties (Response)
contentlength | integer | Gets the content length |
error | integer | Gets the error code (0 means no error) |
errordesc | string | Gets the error description |
requestinfo | json | Returns a JSON string with request and response details |
status | integer | Gets the status code |
text | string | Gets the response text |
Properties (Request)
agent | string | Gets or sets a custom user agent |
autolength | boolean | Enables auto content-lenth generation (for POST requests) |
connection | string | Gets or sets the Connection type (Close, Keep-Alive) |
cookie | string | Gets or sets a cookie |
description | string | Gets or sets a description for the request (This is returned as part of the JSON string from the requestinfo property) |
enablegzip | boolean | Enables or disables GZIP compression |
maxretry | integer | Gets or sets the max number of retries (0 for disabled) |
postdata | string | Gets or sets the POST data to be used in a POST request |
timeout | integer | Gets or sets a timeout value (in ms) |
useproxy | boolean | Enables or disables proxy usage |
version | string | Gets or sets the HTTP version (1.0 or 1.1) |
Properties (Authentication)
auth | string | Gets or sets the type of server authentication (None, Basic, NTLM) |
username | string | Gets or sets an username for server authentication |
password | string | Gets 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()