2013-06-05 4 views
2

좀 프록시 서버를 통해 일부 내용에 접근하기 위해 노력하고있어하지만 난 얻을 :루비 - 증가 프록시 요청 제한 시간

<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.. 

모든 HEL을 recagnize하지 않습니다 피?

답변

1

프록시 (HTTP) 클래스에서 get_response을 호출하면 Net::HTTPResponse 인스턴스가 발생하고 start 또는 open_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) 
+0

감사합니다. gr8. – tokhi