新手问题 open-uri 尝试打开一个国内网站,但提示 Errno::ETIMEDOUT

tianbuxia77 · September 16, 2015 · Last by king1990_cool replied at September 16, 2015 · 1754 hits
require 'open-uri'
open("http://www.baidu.com") do |f|
f.each_line {|line| p line}
  puts f.base_uri
  puts f.content_type
  puts f.charset
  puts f.content_encoding 
  puts f.last_modified
end

运行结果错误:

C:/Ruby193/lib/ruby/1.9.1/net/http.rb:762:in `initialize': A connection attempt
failed because the connected party did not properly respond after a period of ti
me, or established connection failed because connected host has failed to respon
d. - connect(2) (Errno::ETIMEDOUT)
require 'open-uri'
open("http://www.baidu.com") do |f|
  f.each_line {|line| p line}
  puts f.base_uri
  puts f.content_type
  puts f.charset
  puts f.content_encoding 
  puts f.last_modified
end

建议有代码的时候 使用插入代码功能。 代码没有问题,应该是你网络的问题。 Errno::ETIMEDOUT 访问超时了。

好的 谢谢了 但是 我直接访问百度是可以访问的

你有用到 HTTP_PROXY 么?直接连接应该没有问题。

You need to Sign in before reply, if you don't have an account, please Sign up first.