我正在使用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/"
我的代碼有什麼問題?
你可以考慮增加一個超時GET請求,這樣至少應用程序不永遠掛起。改變你的行閱讀http = EventMachine :: HttpRequest.new(url,opts).get,:timeout => 15 – 2012-05-10 10:39:30