即使存在URL,我仍然在Ruby中将错误连接到下面列出的URL。这是为什么?无法通过Ruby获取URL响应
1.9.3p194 :003 > require 'uri'
=> true
1.9.3p194 :004 > require 'net/http'
=> true
1.9.3p194 :005 > url = "https://blogs.oracle.com/ksplice/entry/introducing_redpatch"
=> "https://blogs.oracle.com/ksplice/entry/introducing_redpatch"
1.9.3p194 :006 > url_parsed = URI.parse(url)
=> #<URI::HTTPS:0x00000001939288 URL:https://blogs.oracle.com/ksplice/entry/introducing_redpatch>
1.9.3p194 :007 > response = Net::HTTP.get_response(url_parsed)
Errno::ECONNRESET: Connection reset by peer
有了OpenURI,有可能获得响应代码吗? (对于旧的方法,我使用了'response.code'。) –
是的,它在关于使用'open'的块的文档中。使用'status'方法。 –