lua中的https请求
我正在尝试使用 lua 脚本检索启用 SSL 的服务器上的页面。需要注意的是,服务器有一个自签名证书。由受信任的 CA 颁发的证书没有问题。
local https = require("socket.http")
local resp = {}
local r, c, h, s = https.request{
url = "https://my-server:443/example.php",
sink = ltn12.sink.table(resp),
protocol = "tlsv1"
}
服务器返回:
错误的请求 您的浏览器发送了该服务器无法理解的请求。 原因:您正在向启用 SSL 的服务器端口发送纯 HTTP。 请改用 HTTPS 方案访问此 URL。
在服务器端,该请求会在 Apache ssl_access.log 中生成此条目
192.168.0.150 - - [27/Nov/2011:16:32:07 +0100] "GET /" 400 529 "-" "-"
。此外,tcpdump 显示在 SYN-ACK 握手之后,不会发送任何 SSL 257 Client Hello
。使用浏览器中的相同 URL 或使用 wget 可以正常工作。
I am trying to retrieve a page on my SSL enabled server with a lua script. Important to note that the server has a self-signed certificate. No problem with certificate issued by a trusted CA.
local https = require("socket.http")
local resp = {}
local r, c, h, s = https.request{
url = "https://my-server:443/example.php",
sink = ltn12.sink.table(resp),
protocol = "tlsv1"
}
The server returns:
Bad Request
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.
And on the server side, that request produce this entry in the Apache ssl_access.log
192.168.0.150 - - [27/Nov/2011:16:32:07 +0100] "GET /" 400 529 "-" "-"
Furthermore, tcpdump shows that after the SYN-ACK handshake, no SSL 257 Client Hello
is sent. Using the same URL from my browser or with wget works ok.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如Doug Currie所说,你应该使用luasec。为了启用
https.request
,您必须需要ssl.https
模块:As Doug Currie said, you should use luasec. In order to enable
https.request
, you have to require thessl.https
module:请参阅 此 lua-l 线程 描述如何添加支持对于使用 luasec 的 luasocket https 客户端。
See this lua-l thread describing how to add support for luasocket https client using luasec.
像这样
like this
更现代的解决方案是使用 lua-http: https://github.com/daurnimator/lua-http< /a>
它带有一个 luasocket/luasec 兼容接口。
A more modern solution is to use lua-http: https://github.com/daurnimator/lua-http
It comes with a luasocket/luasec compatible interface.