Ruby 通过代理打开 uri 下载
我不知道如何使用 open-uri 和主动代理从 URL 下载数据。
我使用了这段代码:
proxy = Net::HTTP::Proxy("??????????????????????")
proxy.start('http://www.example.com') { |http|
puts open(strURL).read
}
但 Ruby 返回了错误: c:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in `initialize': 连接尝试失败,因为连接方在一段时间,或由于连接的主机未能响应而建立的连接失败。 - connect(2) (Errno::ETIMEDOUT)
出了什么问题?(我不想使用 HTTP)(
I don't know how to download data from URL using open-uri and active proxy.
I used this code:
proxy = Net::HTTP::Proxy("??????????????????????")
proxy.start('http://www.example.com') { |http|
puts open(strURL).read
}
but Ruby returned error: c:/Ruby192/lib/ruby/1.9.1/net/http.rb:644:in `initialize': A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. - connect(2) (Errno::ETIMEDOUT)
What's wrong ?( I don't want to use HTTP)(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this :
上面的回答评论没有帮助,它们没有显示如何将代理信息指定为 OpenURI open() 方法的一部分。这个SO线程确实回答了这个问题:
使用 OpenURI 或 net/http 的 Ruby 代理身份验证 GET/POST
Answer comments above are not helpful, they do not show how to specify the proxy info as part of OpenURI open() method. This SO thread does answer the question:
Ruby Proxy Authentication GET/POST with OpenURI or net/http