0 0

Net::HTTP::Proxy doesn't work5

想使用Net::HTTP的代理功能访问网页,代码如下

require 'net/http'

proxy_addr = '12.161.250.205'
proxy_port = 1080

url = URI.parse('http://www.iteye.com')
res = Net::HTTP::Proxy(proxy_addr , proxy_port ).start(url.host, url.port) {|http|
http.get('/')
}


结果报错如下:

c:/ruby/lib/ruby/1.8/net/protocol.rb:135:in `sysread': end of file reached (EOFE
rror)
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
        from c:/ruby/lib/ruby/1.8/timeout.rb:62:in `timeout'
        from c:/ruby/lib/ruby/1.8/timeout.rb:93:in `timeout'
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
        from c:/ruby/lib/ruby/1.8/net/protocol.rb:126:in `readline'
        from c:/ruby/lib/ruby/1.8/net/http.rb:2020:in `read_status_line'
        from c:/ruby/lib/ruby/1.8/net/http.rb:2009:in `read_new'
        from c:/ruby/lib/ruby/1.8/net/http.rb:1050:in `request'
        from c:/ruby/lib/ruby/1.8/net/http.rb:772:in `get'
        from web1.rb:22
        from c:/ruby/lib/ruby/1.8/net/http.rb:543:in `start'
        from c:/ruby/lib/ruby/1.8/net/http.rb:440:in `start'
        from web1.rb:21

Thanks in Advance
2008年11月16日 11:55

2个答案 按时间排序 按投票排序

0 0

采纳的答案

程式碼十分正常。試試用telnet,駁上proxy,取檔有沒有問題。

$ telnet 12.161.250.205 1080
GET http://www.java.com/ http/1.1

按兩下Enter。看看結果是否正常。

若是生產用,試用begin/rescue/end來補救錯誤。

2008年11月20日 16:02
0 0

代理不稳定时,会有这种情况发生。

2008年11月16日 21:07

相关推荐

    [ NoFuserEx - v1.1 ]

    [ NoFuserEx - v1.1 ] ...If something doesn't work properly, you can notify me or fix it yourself. This is an open-source, if you paid for this, you got ripped off :P Press any key to exit...

    html2canvas

    It doesn't magically circumvent any browser content policy restrictions either, so rendering cross-origin content will require a proxy to get the content to the same origin. The script is still in a...

    TICQClient Version

    ] Sorry that HTTP proxy support wasn‘t added in this release, it‘s impossible due to blocking sockets architecture, but ICQ HTTP PROXY protocol has been discovered and parsed (for developers: see ...

    php.ini-development

    Currently, [PATH=] and [HOST=] sections only work under ; CGI/FastCGI. ; http://php.net/ini.sections ; Directives are specified using the following syntax: ; directive = value ; Directive names are ...

    Senfore_DragDrop_v4.1

    * When TDropFileTarget.GetDataOnEnter is set to True, the component doesn't work with WinZip. Although the file names are received correctly by TDropFileTarget, WinZip doesn't extract the files and...

    计算机网络第六版答案

    Third, if ISPs decide to charge more money to highly profitable content providers (in countries where net neutrality doesn't apply), the content providers can avoid these extra payments. 16. The ...

    ICS delphixe10源码版

    Here is the direct URL at Amazon UK (nearest to my home, please don't use another): http://www.amazon.co.uk/exec/obidos/gc-email-order1/ref=g_gc_email/202-6198323-6681414 For more generous amount, ...

    Vue 2.0在IE11中打开项目页面空白的问题解决

    这个问题的出现是因为Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,例如Iterator、Generator、Set、Maps、Proxy、Reflect、Symbol、Promise等全局对象,以及一些定义在全局对象上的方法(比如...

    simplewebrtc.js webrtc网页视频开发帮助工具

    console.error('Your browser doesn\'t seem to support WebRTC'); } // set options for (item in options) { this.config[item] = options[item]; } // log if configured to if (this.config.log) ...

Global site tag (gtag.js) - Google Analytics