Lua使用代理进行https请求时返回501错误代码

我使用socket.http获取带代理的https url中的信息: 这是我的代码:

   local https = require("socket.http")
   local r, c, h, s = https.request{
   url = "https://www.google.fr",
   proxy="http://proxy:3128/"
   }

   print(r, c, h, s)

我遇到了一个错误:“HTTP/1.1 501 Not Implemented Unsupported Request Method and Protocol, Squid does not support all request methods for all access protocols.”

但是当我测试带有代理的http url时:

   url = "http://www.google.fr",
   proxy="http://proxy:3128/"

或者没有代理的https url时:

   url = "https://www.google.fr"

它就可以了。

似乎只有带代理的https无法使用。或许socket.http不支持带代理的https,或者我的代理服务器不支持从lua socket请求的https?

但是当我在lua中使用curl来要求带代理的https URL时:os.capture("curl -x http://proxy.com:3128" -XGET https://www.google.fr),它就可以了。

所以有人能帮我吗?谢谢!!!

点赞
用户1442917
用户1442917

socket.http不支持https。你需要使用luasec及其ssl.https模块代替。

2017-12-03 20:54:11