Lua
Lua
Send a Form-URL-Encoded REST Request
See more REST Examples
Demonstrates Rest.FullRequestFormUrlEncoded, which sends an application/x-www-form-urlencoded request. The body is built from the query parameters added to the object, and the response body is returned as text.
Background. For a form-url-encoded request the accumulated parameters become the request body rather than the URL query string. This matches the encoding used by HTML form POSTs.
Chilkat Lua Downloads
local chilkat = require("chilkat")
local rest = chilkat.Rest.new()
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
-- The application/x-www-form-urlencoded body is built from the query parameters added to the object.
rest:add_query_param("username", "alice")
rest:add_query_param("action", "login")
-- Send the form-url-encoded request. The parameters become the request body rather than the URL
-- query string.
local responseText = rest:full_request_form_url_encoded("POST", "/api/login")
if not rest.last_method_success then
print(rest.last_error_text)
return
end
print(responseText)