【问题标题】:Ruby - increasing proxy request timeoutRuby - 增加代理请求超时
【发布时间】:2013-06-01 03:44:10
【问题描述】:

我正在尝试通过一些代理服务器访问一些内容,但我得到了:

<Errno::ETIMEDOUT: Connection timed out - connect(2)>

我修改了代码并尝试增加超时时间如下:

require 'open-uri'
require 'net/http'


response = Net::HTTP::Proxy(proxy_ip, proxy_port).get_response(uri.host, uri.path)
response.start(uri.host) do |http|
  http.open_timeout = 5 
  http.read_timeout = 10
end

现在它无法识别open_timeoutstart

undefined method `open_timeout=' for #<Net::HTTPOK 200 OK readbody=true>>
undefined method `start..

有什么帮助吗?

【问题讨论】:

    标签: ruby-on-rails ruby proxy net-http


    【解决方案1】:

    当您在 Proxy(HTTP) 类上调用 get_response 时,您会得到一个 Net::HTTPResponse 实例,但它不会响应 startopen_timeout=

    使用Net::HTTP::Proxy 创建代理HTTP 类,创建该类的实例,然后修改该实例的超时设置。然后您可以使用该实例从代理后面获取内容。

    proxy_http = Net::HTTP.Proxy(proxy_ip, proxy_port).new(uri.host)
    proxy_http.open_timeout = 5
    proxy_http.read_timeout = 10
    response = proxy_http.get(uri.path)
    

    【讨论】:

      猜你喜欢
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      相关资源
      最近更新 更多