Version: beta
FUNCTIONS | |
---|---|
http.request() | perform a HTTP/HTTPS request |
http.request(url,method,callback,[headers],[post_data],[options])
Perform a HTTP/HTTPS request.
If no timeout value is passed, the configuration value "network.http_timeout" is used. If that is not set, the timeout value is 0
(which blocks indefinitely).
PARAMETERS
url |
string |
target url |
method |
string |
HTTP/HTTPS method, e.g. "GET", "PUT", "POST" etc. |
callback |
function(self, id, response) |
response callback function
|
[headers] |
table |
optional table with custom headers |
[post_data] |
string |
optional data to send |
[options] |
table |
optional table with request parameters. Supported entries:
|
EXAMPLES
Basic HTTP-GET request. The callback receives a table with the response in the fields status, the response (the data) and headers (a table).local function http_result(self, _, response)
if response.bytes_total ~= nil then
update_my_progress_bar(self, response.bytes_received / response.bytes_total)
else
print(response.status)
print(response.response)
pprint(response.headers)
end
end
function init(self)
http.request("http://www.google.com", "GET", http_result, nil, nil, { report_progress = true })
end