EventMachine HTTP请求无法通过HTTPS连接代理服务器

问题描述:

我正在使用em-http,但无法在代理服务器后面获得HTTPS(SSL)连接。这是我的代码。EventMachine HTTP请求无法通过HTTPS连接代理服务器

require 'eventmachine' 
require 'em-http' 

url = "https://twitter.com/" 
opts = { 
    :proxy => { :host => 'my.proxy', :port => 8080 } 
} 

EventMachine.run do 
    http = EventMachine::HttpRequest.new(url, opts).get 
    http.callback { 
    puts http.response 
    EventMachine.stop 
    } 
end 

此代码没有错误,但它什么也不做,并且不会退出eventmachine主循环。

当我在下面的条件下尝试它时,我的应用程序可以连接到目标。

  • 外代理/通过HTTPS
  • 背后代理/通过HTTP

我也可以用后面代理卷曲得到响应。

curl "https://twitter.com/" 

我的代码有什么问题?

+0

你可以考虑增加一个超时GET请求,这样至少应用程序不永远挂起。改变你的行阅读http = EventMachine :: HttpRequest.new(url,opts).get,:timeout => 15 – 2012-05-10 10:39:30

指定errback。你的代码,然后将退出事件循环,并打印代理请求可能遇到的任何问题:

http.errback { 
    p http.response_header.status 
    p http.response_header 
    p http.response 

    EventMachine.stop 
} 

更改呼叫:

http = EventMachine::HttpRequest.new(url).get opts 
+1

如果你能解释一下为什么这个工作原理,这将是有帮助的。 – 2012-10-20 12:11:41