I've got a question about Lua and https. I'm developing some software for a router which supports Lua. The bad thing is that this router doesn't support debugging. So I was looking for an IDE for Lua.
I'm using the Lua Development Tools and LuaForWindows on a Win 7 64-bit OS. Till now everything works like it should. But now I have to call some urls by https. The router itself has a package ssl.lua and you can user this …
我正在尝试从我的 lua 代码访问网页的内容。以下代码适用于非 HTTPS 页面
local http=require("socket.http")
body,c,l,h = http.request("http://www.example.com:443")
print("status line",l)
print("body",body)
Run Code Online (Sandbox Code Playgroud)
但是在 HTTPS 页面上,我收到以下错误。
您的浏览器发送了此服务器无法理解的请求。
原因:您对启用 SSL 的服务器端口使用纯 HTTP。
请改用 HTTPS 方案访问此 URL。
现在我做了我的研究,有些人建议使用 Luasec,但无论我尝试了多少,我都无法让它工作。此外,Luasec 的库比我正在寻找的要复杂一些。我试图获取的页面仅包含一个 json 对象,如下所示:
{
"value" : "false",
"timestamp" : "2017-03-06T14:40:40Z"
}
Run Code Online (Sandbox Code Playgroud) 在我的脚本中,我使用库 LuaSocket 发送 XML 代码。这适用于以下代码:
local request_body = (XMLHeader..XMLBody);
local response_body = {}
local res, code, response_headers = socket.http.request
{
url = "http://blabla.com/v01/Authenticatie.svc";
method = "POST";
headers =
{
["Content-Type"] = "application/soap+xml; charset=utf-8";
["Content-Length"] = string.len(request_body);
["Accept-Encoding"] = "gzip, deflate";
["Connection"] = "Keep-Alive";
};
source = ltn12.source.string(request_body);
sink = ltn12.sink.table(response_body);
}
Run Code Online (Sandbox Code Playgroud)
但是现在我将使用带有证书的协议 HTTPS 发送 XML。我知道我可以使用 LuaSec 但如何使用?有人可以告诉我,我如何将代码修改为 HTTPS 的工作代码?