Ruby - increasing proxy request timeout

穿精又带淫゛_ 提交于 2019-12-06 09:50:59

When you call get_response on the Proxy(HTTP) class, you get a Net::HTTPResponse instance, and it doesn't respond to start or open_timeout=.

Use Net::HTTP::Proxy to create an proxied HTTP class, create an instance of that class, and then modify the timeout settings on that instance. And then you can use the instance to fetch contents from behind a proxy.

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!