Sample code for 30+ languages & platforms
Lua

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat Lua Downloads

Lua
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()

-- To use HTTP Basic authentication:
http.login = "myLogin"
http.password = "myPassword"
http.basic_auth = true

-- Run the test using this URL with the credentials above.
-- (Works while httpbin.org keeps the test endpoint available.)
local jsonResponse = http:quick_get_str("https://httpbin.org/basic-auth/myLogin/myPassword")
if not http.last_method_success then
    print(http.last_error_text)
    return
end

print("Response status code: " .. http.last_status)

print(jsonResponse)

-- Output:

-- Response status code: 200
-- {
--   "authenticated": true,
--   "user": "myLogin"
-- }