Hello
I am trying to do some basic http stuff with Ruby but I can’t get the
following example from the Programming Ruby book to work.
Code from the book:
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]
I get this error:
c:/ruby/lib/ruby/1.8/net/protocol.rb:83:in initialize': getaddrinfo: no address associated with hostname. (SocketError) from c:/program files/ruby/lib/ruby/1.8/net/protocol.rb:83:in
new’
from c:/program files/ruby/lib/ruby/1.8/net/protocol.rb:83:in
connect' from c:/program files/ruby/lib/ruby/1.8/net/protocol.rb:82:in
timeout’
from c:/program files/ruby/lib/ruby/1.8/timeout.rb:55:in timeout' from c:/program files/ruby/lib/ruby/1.8/net/protocol.rb:82:in
connect’
from c:/program files/ruby/lib/ruby/1.8/net/protocol.rb:64:in
initialize' from c:/program files/ruby/lib/ruby/1.8/net/http.rb:430:in
open’
from c:/program files/ruby/lib/ruby/1.8/net/http.rb:430:in do_start' from c:/program files/ruby/lib/ruby/1.8/net/http.rb:419:in
start’
from c:/program files/ruby/lib/ruby/1.8/net/http.rb:821:in request' from c:/program files/ruby/lib/ruby/1.8/net/http.rb:618:in
get’
from http_msg.rb:4
Exit code: 1
Details:
Ruby: version 1.8.1 (2004-01-27)
OS: Win XP Pro
I’m behind a proxy with the only information I have about it are IP
address and port number.
Many thanks for your help!
K