Sample code for 30+ languages & platforms
Lua

Disconnect from a REST Server

See more REST Examples

Demonstrates Rest.Disconnect, which closes the current HTTP connection. The argument is the maximum number of milliseconds to wait for the close to complete.

Background. Connections are normally kept alive for reuse. Disconnect is used when an application wants to explicitly release the connection rather than relying on keep-alive or object destruction.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local rest = chilkat.Rest.new()

-- Connect to the REST server.  The 3rd argument enables TLS (use true for HTTPS on port 443),
-- and the 4th enables automatic reconnection if the connection is dropped between requests.
local bTls = true
local bAutoReconnect = true
local success = rest:connect("example.com", 443, bTls, bAutoReconnect)
if not success then
    print(rest.last_error_text)
    return
end

local responseText = rest:full_request_no_body("GET", "/api/status")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

print(responseText)

-- Close the connection.  The argument is the maximum number of milliseconds to wait for the
-- close to complete.
local bDisconnected = rest:disconnect(200)
if not bDisconnected then
    print("The disconnect did not complete within the wait time.")
end

print("Done.")