- Select ref document -

HTTP API documentation

version 1.2.149

Functions for performing HTTP and HTTPS requests.

Functions

http.request

http.request(url, method, callback, [headers], [post_data], [options])

Perform a HTTP/HTTPS request.

The following cipher suites are supported for HTTPS requests:

  • TLS_RSA_WITH_AES_128_CBC_SHA
  • TLS_RSA_WITH_AES_256_CBC_SHA
  • TLS_RSA_WITH_AES_128_CBC_SHA256
  • TLS_RSA_WITH_AES_256_CBC_SHA256

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

self
object The current object
id
hash Internal message identifier. Do not use!
response
table The response data. Contains the fields:
  • number status: the status of the response
  • string response: the response data
  • table headers: all the returned headers
[headers]

table optional table with custom headers

[post_data]

string optional data to send

[options]

table optional table with request parameters. Supported entries:

  • number timeout: timeout in seconds
url

string target url

method

string HTTP/HTTPS method, e.g. "GET", "PUT", "POST" etc.

callback

function(self, id, response) response callback function

self
object The current object
id
hash Internal message identifier. Do not use!
response
table The response data. Contains the fields:
  • number status: the status of the response
  • string response: the response data
  • table headers: all the returned headers
[headers]

table optional table with custom headers

[post_data]

string optional data to send

[options]

table optional table with request parameters. Supported entries:

  • number timeout: timeout in seconds

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)
    print(response.status)
    print(response.response)
    pprint(response.headers)
end

function init(self)
    http.request("http://www.google.com", "GET", http_result)
end