Ruby 通过代理打开 uri 下载

发布于 2024-12-23 04:56:34 字数 409 浏览 5 评论 0原文

我不知道如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

完美的未来在梦里 2024-12-30 04:56:34

试试这个:

require 'open-uri'
p = open('http://www.example.com', 
          proxy: URI.parse("http://190.72.158.80:8080")
        )

Try this :

require 'open-uri'
p = open('http://www.example.com', 
          proxy: URI.parse("http://190.72.158.80:8080")
        )
眼眸里的那抹悲凉 2024-12-30 04:56:34

上面的回答评论没有帮助,它们没有显示如何将代理信息指定为 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文