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屋!