Lua Requires Chilkat v11.2.0+
Lua
Example: Http.SetAuthTokenSb method
Demonstrates theSetAuthTokenSb method.
Chilkat Lua Downloads
local chilkat = require("chilkat")
local success = false
local http = chilkat.Http.new()
local oauth2_access_token = "ya39.Ci-XA_C5bGgRDC3UaD-h0_NeL-DVIQnI2gHtBBBHkZzrwlARkwX6R3O0PCDEzRlfaQ"
local sbAccessToken = chilkat.StringBuilder.new()
sbAccessToken:append(oauth2_access_token)
-- Causes the "Authorization: Bearer <access_token>" header to be added to all HTTP requests.
http:set_auth_token_sb(sbAccessToken)
local responseText = http:quick_get_str("https://chilkatsoft.com/helloWorld.txt")
if not http.last_method_success then
print(http.last_error_text)
return
end
-- See the HTTP request header that was sent.
print(http.last_header)
-- Output:
--
-- GET /helloWorld.txt HTTP/1.1
-- Host: chilkatsoft.com
-- Accept: */*
-- Accept-Encoding: gzip
-- Authorization: Bearer ya39.Ci-XA_C5bGgRDC3UaD-h0_NeL-DVIQnI2gHtBBBHkZzrwlARkwX6R3O0PCDEzRlfaQ
-- Note: The information that should be kept secret in the Authorization header
-- will be redacted. Thus, the LastHeader property will show the following:
-- Authorization: Bearer ****