Functions for performing HTTP and HTTPS requests.
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).
url - target url
method - HTTP/HTTPS method, e.g. "GET", "PUT", "POST" etc.
callback - response callback function
self
id
response
status
: the status of the responseresponse
: the response data (if not saved on disc)headers
: all the returned headerspath
: the stored path (if saved to disc)error
: if any unforeseen errors occurred (e.g. file I/O)[headers] - optional table with custom headers
[post_data] - optional data to send
[options] - optional table with request parameters. Supported entries:
timeout
: timeout in secondspath
: path on disc where to download the file. Only overwrites the path if status is 200. Not available in HTML5 buildignore_cache
: don't return cached data if we get a 304. Not available in HTML5 buildchunked_transfer
: use chunked transfer encoding for https requests larger than 16kb. Defaults to true. Not available in HTML5 buildBasic 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)
print(response.status)
print(response.response)
pprint(response.headers)
end
function init(self)
http.request("http://www.google.com", "GET", http_result)
end