Logo Anfibia Reactor ™ - User Guide
Copyright © 2013 Anfibia Software. All Rights Reserved.
www.anfibia-soft.com
Plugins : API : HttpClient.request

Summary

Sends an HTTP request and obtains a response.

Syntax

local httpResponse = httpClient:request(url)

Parameters

httpClient : A previously created HttpClient object.
url : URL of the resource to request.

Returns

httpResponse : A table with the corresponding HTTP response.
errorMessage : In case of connection error, a description of the error cause.

Description

Connects and sends a request to an HTTP server indicated by the URL parameter. The result of the operation is returned as a response table containing the following elements:

In case of a connection or unexpected error, this function will return 2 values: nil, errorMessage . Where errorMessage is a string with a description of the error cause.

Examples

local httpClient = HttpClient.new()

local httpResponse, errorMessage = httpClient:request('http://en.wikipedia.org/wiki/Special:Random')

if not httpResponse then
  print('Unable to connect, cause: ' .. errorMessage)
else
  print('Content type: ' .. httpResponse.content_type)
  print('Server: ' .. httpResponse.server)
  print('Language: ' .. httpResponse.headers['Content-Language'])
  print('Content: ' .. httpResponse.content)
end

 

See Also

HttpClient.new