微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Lua - 请求通过 curl 工作,但不是通过 LuaLua 套接字?

如何解决Lua - 请求通过 curl 工作,但不是通过 LuaLua 套接字?

我正在尝试使用 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 举报,一经查实,本站将立刻删除。