Lua
" header.
Lua
HTTP GET with Custom Header and OAuth2 Bearer Token
See more HTTP Examples
Demonstrate how to send a GET request with customer headers and an "Authorization: BearerChilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Setting the AuthToken property causes the "Authorization: Bearer <token>" header to be adeded.
http.auth_token = "Just_the_access_token_here"
-- Add one or more custom headers..
http:set_request_header("X-Tenant-ID", "value goes here")
http:set_request_header("blah-blah-blah", "value goes here")
local url = "https://www.example.com/abc/123?x=something&y=someOtherThing"
-- Send the GET request and get the response body in the StringBuilder object.
local sb = chilkat.StringBuilder.new()
local success = http:quick_get_sb(url, sb)
if not success then
print(http.last_error_text)
return
end
print("response status code: " .. http.last_status)
print("response body:")
print(sb:get_as_string())
-- If the response contains JSON, you can load it into a Chilkat JSON object...
local json = chilkat.JsonObject.new()
json:load_sb(sb)
json.emit_compact = false
print(json:emit())