星期日, 七月 22, 2007

get_response

require 'net/https'
response = Net::HTTP.get_response('http://www.sina.com.cn','index.html')
puts response.body

ruby抱错了:
c:/ruby/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: no address as
sociated with hostname. (SocketError)
from c:/ruby/lib/ruby/1.8/net/http.rb:560:in `open'
from c:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
from c:/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
from c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
from c:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
from c:/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
from c:/ruby/lib/ruby/1.8/net/http.rb:542:in `start'
from c:/ruby/lib/ruby/1.8/net/http.rb:374:in `get_response'
from D:/my ruby/get.rb:3


不需要http://否则会出错的!

response = Net::HTTP.get_response('www.sina.com.cn','index.html')
这样就可以了。

没有评论: