我正在尝试使用 Lua与Cleverbot API进行交互。我有一个密钥和一个用户名,所以我用 Postman 进行了测试,它运行良好。然后我尝试对 Lua 做同样的事情,但我遇到了一个奇怪的错误。
这是代码:
local https = require("ssl.https")
local string = require("string")
local ltn12 = require ("ltn12")
local funcs = (loadfile "./libs/functions.lua")()
local function cleverbot(msg)
local params = {
['user'] = 'SyR2nvN1cAxxxxxx',
['key'] = 'ckym8oDRNvpYO95GmTD14O9PuGxxxxxx',
['nick'] = 'cleverbot',
['text'] = tostring(msg),
}
local body = funcs.encode_table(params)
local response = {}
ok, code, headers, status = https.request({
method = "POST",
url = "https://cleverbot.io/1.0/ask/",
headers = {
['Accept'] = '*/*',
['content-type'] = 'application/x-www-form-urlencoded',
['accept-encoding'] = 'gzip',
['content-length'] = tostring(#body),
},
print(tostring(ok)),
print(tostring(code)),
print(tostring(headers)),
print(tostring(status)),
source = ltn12.source.string(body),
sink = ltn12.sink.table(response)
})
response = table.concat(response)
if code ~= 200 then
return
end
if response[1] ~= nil then
return tostring(response)
end
end
但是,当我调用它时,这就是这 4 个打印显示的内容:
nil
tlsv1 alert internal error
nil
nil
我尝试使用 HTTP 进行连接,但这就是发生的情况:
1
301
table: 0xe5f7d60
HTTP/1.1 301 Moved Permanently
response
总是空的。请问,我做错了什么?谢谢!