Sample code for 30+ languages & platforms
Lua

Get a REST Response Header by Name

See more REST Examples

Demonstrates Rest.ResponseHdrByName, which returns the value of a response header field by name. Header field names are case-insensitive.

Background. Response headers are available after ReadResponseHeader has read the status line and headers. Lookup by name is convenient when a specific header, such as Content-Type, is needed.

Chilkat Lua Downloads

Lua
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

success = rest:send_req_no_body("GET", "/api/items/123")
if not success then
    print(rest.last_error_text)
    return
end

local statusCode = rest:read_response_header()
if statusCode < 0 then
    print(rest.last_error_text)
    return
end

-- Return the value of a response header field by name.  Header field names are case-insensitive.
local contentType = rest:response_hdr_by_name("Content-Type")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

print("Content-Type: " .. contentType)