我正嘗試使用Lua與Cleverbot API進行交互。我有一個密鑰和一個用戶名,所以我測試了郵差,它的工作完美。然後我試圖用Lua做同樣的事情,但我有一個奇怪的錯誤。Lua - HTTPS/tlsv1警報內部錯誤
這是代碼:
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
總是空的。請問我做錯了什麼? 謝謝!
你調用https.request的方式肯定是錯誤的。爲什麼要將打印函數的結果傳遞給https.request參數表? – marsgpl
哦,嘿@marsgpl,我不知道這可能會影響結果。我刪除了它,並在其外面放置了一個「打印(確定,代碼,標題,狀態)」。我也刪除了'funcs.encode_table(params)'的東西,我正在測試一個已經格式化的參數字符串。我也在裏面加了'protocol =「tlsv1」',但結果完全一樣。還有什麼錯誤? – bokirov
好吧,試着檢查openssl庫的存在,確保它沒有過期。 – marsgpl