Skip to content

http_request

http_request(options) performs an arbitrary HTTP request with full control over method, URL, body, headers, proxy, timeout, and response size limit. Returns (response, nil) on success or (nil, error_table) on failure.

http_request(options)
async
Field Type Required Description
method string No HTTP method (GET, HEAD, POST, PUT, DELETE, etc.). Defaults to GET
url string Yes Target URL
body string / nil Conditional Request body (binary-safe, required for POST/PUT/PATCH)
headers table / nil No Optional key-value header pairs
proxy string / nil No Proxy URL (e.g. "http://user:pass@proxy:8080")
timeout number / nil No Timeout in seconds (default: 30)
max_body_size number / nil No Max response body in MB (integer, default: 10)

Same as http_get.

-- HEAD request (no body)
local res, err = http_request({ method = "HEAD", url = "https://example.com" })
if not res then
log("head failed: " .. err.error)
return
end
-- POST with JSON body through a proxy
local res, err = http_request({
method = "POST",
url = "https://api.example.com/data",
body = '{"key":"value"}',
headers = { ["Content-Type"] = "application/json" },
proxy = "http://user:pass@residential-proxy:8080",
timeout = 15
})
if not res then
log("request failed: " .. err.kind)
return
end