I’m trying to interact with the Sipgate api (https://developer.sipgate.io/ ) using Lua, and an example they provide for authentication uses Curl, which works. (Not my b64 user/pass)
curl \
--request GET \
--header "Accept: application/json" \
--header "Authorization: Basic Sm9objp0b3BzZWNyZXQ=" \
https://api.sipgate.com/v2/account
But when I try it via Lua, I get the following error. Does anyone have an idea of what i’m missing
Message/response..
ok 1
statusCode 301
statusText HTTP/1.1 301 Moved Permanently
headers: table: 0x2692948
location https://api.sipgate.com:80/v2/account/
connection close
content-length 0
Lua code used..
local https = require "ssl.https"
local mime = require("mime")
local http = require "socket.http"
local data = ""
local username = "user"
local password = "pass"
local function collect(chunk)
if chunk ~= nil then
data = data .. chunk
end
return true
end
local ok, statusCode, headers, statusText = http.request {
method = "GET",
url = "https://api.sipgate.com/v2/account",
headers = {
["Accept"] = "application/json",
["Authorization"] = "Basic " .. (mime.b64(username ..":" .. password)),
},
sink = collect
}
--debug -
print("enc64", mime.b64(username ..":" .. password))
print("ok\t", ok);
print("statusCode", statusCode)
print("statusText", statusText)
print("headers:", headers)
print("data", data)