Sample code for 30+ languages & platforms
Lua

Configure HTTP Basic Authentication with SecureString

See more REST Examples

Demonstrates Rest.SetAuthBasicSecure, which configures HTTP Basic authentication using SecureString objects instead of plaintext strings.

Background. A SecureString keeps sensitive values encrypted in memory, reducing the window in which credentials appear as readable plaintext. This is otherwise equivalent to SetAuthBasic.

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

-- SetAuthBasicSecure configures HTTP Basic authentication using SecureString objects, which keep
-- the credentials encrypted in memory.
-- Normally you would not hard-code secrets in source.  You should instead obtain them from an
-- interactive prompt, environment variable, or a secrets vault.
local ssUsername = chilkat.SecureString.new()
ssUsername:append("myUsername")
local ssPassword = chilkat.SecureString.new()
ssPassword:append("myPassword")

success = rest:set_auth_basic_secure(ssUsername, ssPassword)
if not success then
    print(rest.last_error_text)
    return
end

local responseText = rest:full_request_no_body("GET", "/api/protected")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

print(responseText)