lua 中的 https 请求 [英] https request in lua
问题描述
我正在尝试使用 lua 脚本检索启用 SSL 的服务器上的页面.重要的是要注意服务器有一个自签名证书.由受信任的 CA 颁发的证书没有问题.
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"
}
服务器返回:
错误的请求您的浏览器发送了此服务器无法理解的请求.原因:您对启用 SSL 的服务器端口使用纯 HTTP.请改用 HTTPS 方案访问此 URL.
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.
在服务器端,该请求会在 Apache ssl_access.log 中生成此条目
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 "-" "-"
此外,tcpdump 显示在 SYN-ACK 握手之后,没有发送 SSL 257 Client Hello
.从我的浏览器或 wget 使用相同的 URL 可以正常工作.
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.
推荐答案
正如 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 the ssl.https
module:
local https = require 'ssl.https'
local r, c, h, s = https.request{
url = "https://my-server:443/example.php",
sink = ltn12.sink.table(resp),
protocol = "tlsv1"
}
这篇关于lua 中的 https 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!