问题描述
我正在尝试使用 Lua 与 Sipgate api (https://developer.sipgate.io/ ) 交互,并且他们提供的用于身份验证的示例使用 Curl,它有效。 (不是我的 b64 用户/通行证)
curl \
--request GET \
--header "Accept: application/json" \
--header "Authorization: Basic Sm9objp0b3BzZWNyZXQ=" \
https://api.sipgate.com/v2/account
但是当我通过 Lua 尝试时,出现以下错误。 有没有人知道我错过了什么
消息/回复..
好的 1
状态码 301
statusText HTTP/1.1 301 永久移动
标题:表:0x2692948
位置https://api.sipgate.com:80/v2/account/
连接关闭
内容长度 0
使用 Lua 代码..
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)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)