Summary
Creates an HTTP client object.
Syntax
local httpRequest = HttpClient.new()Parameters
none
Returns
httpClient : HttpClient object (Lua table).
Description
Creates an HttpClient object that can be used to send HTTP requests. The object returned is a table that contains the following elements:
- method: A valid HTTP method such as 'GET', 'POST', 'PUT', 'HEAD' or 'DELETE'. By default a 'GET' request.
- params: A table with parameters to send with the request.
- headers: A table with HTTP headers to send with the request.
- connect_timeout: Maximum time to wait for the successful completion of a connection attempt, in millseconds.
- read_timeout: Maximum time to wait for the successful completion of a read attempt (once connected), in millseconds.
- follow_redirects: Indicates if the client should handle redirection responses from the server to a different location.
- max_redirects: Specifies the maximum number of redirect responses the client should follow.
- username: Authorization identity used for Basic Access Authentication.
- password: Credentials used for Basic Access Authentication.
- request() method
Examples
local httpClient = HttpClient.new()
httpClient.params.title = 'Lua'
httpClient.params.action = 'raw'
httpClient.headers['user-agent'] = 'Reactor plugin'
local httpResponse = httpClient:request('http://en.wikipedia.org/w/index.php')
print('Content type: ' .. httpResponse.content_type)
print('Wiki text: ' .. httpResponse.content)
See Also