Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use access url using Ruby

8 views
Skip to first unread message

sujeet kumar

unread,
Jun 2, 2005, 8:12:36 AM6/2/05
to
hi
I am new to Ruby. I want to access http address using Ruby program .
I run the sample code of book The Pragmatic Programmer's Guide but it
doesn't work.
code is:
require 'net/http'

h = Net::HTTP.new('www.pragmaticprogrammer.com', 80)
resp, data = h.get('/index.html', nil )
puts "Code = #{resp.code}"
puts "Message = #{resp.message}"
resp.each {|key, val| printf "%-14s = %-40.40s\n", key, val }
p data[0..55]

Error is:
c:/ruby/lib/ruby/1.8/net/protocol.rb:83:in `initialize': getaddrinfo: no address
associated with hostname. (SocketError)
from c:/ruby/lib/ruby/1.8/net/protocol.rb:83:in `new'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:83:in `connect'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:82:in `timeout'
from c:/ruby/lib/ruby/1.8/timeout.rb:55:in `timeout'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:82:in `connect'
from c:/ruby/lib/ruby/1.8/net/protocol.rb:64:in `initialize'
from c:/ruby/lib/ruby/1.8/net/http.rb:430:in `open'
from c:/ruby/lib/ruby/1.8/net/http.rb:430:in `do_start'
from c:/ruby/lib/ruby/1.8/net/http.rb:419:in `start'
from c:/ruby/lib/ruby/1.8/net/http.rb:821:in `request'
from c:/ruby/lib/ruby/1.8/net/http.rb:615:in `get'
from url.rb:4

For information , I access internet through proxy server . Can anybody
tell me the error?
thanks

sujeet


Robert Klemme

unread,
Jun 2, 2005, 8:21:19 AM6/2/05
to

See "Accessing via Proxy" on
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html

Also preferrable use the block form to ensure proper closing of socket
connections.

Kind regards

robert

0 new messages