send

The send method sends the HTTP request.

Syntax

send()

Returns

(LuaHttpResponse). A LuaHttpResponse object.

The send method can throw an exception if the request fails. You can catch an exception by calling the method using the Lua function pcall.

Example

The following example shows how to send a request:

local config_string = [===[
[HTTP]
ProxyHost=proxy
ProxyPort=8080
SSLMethod=NEGOTIATE
]===]

local config = LuaConfig:new(config_string)
local request = LuaHttpRequest:new(config, "HTTP")
request:set_url("https://www.example.com")
request:set_method("GET")

local result, response = pcall(LuaHttpRequest.send, request)

if (result) then
    print ("Success: " , response:get_http_code())
else
    print ("Error: " , response)
end

When the send method is successful, the result variable is true and response is a LuaHttpResponse object. If an exception is thrown from the send method, the result variable is false and response contains the error message.