In article <21219900.0402070224.63f66963 / posting.google.com>, kris <kris_80 / btinternet.com> wrote: >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: Note that a couple of things have changed in Net::HTTP since the book came out, see changes below: > >require 'net/http' > >h = Net::HTTP.new('www.pragmaticprogrammer.com', 80) >resp, data = h.get('/index.html', nil ) HTTP#get now only returns a single Net::HTTPResponse object, but don't worry, you can still get at the data (Or body of the page) by doing: resp = h.get('/index.html',nil) puts resp.body >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. It's not working because you're behind a firewall. You need to use a proxy like so: require 'net/http' proxy_addr = 'your.proxy.host' proxy_port = 8080 : Net::HTTP::Proxy(proxy_addr, proxy_port).start('www.example.com') {|http| # always connect to your.proxy.addr:8080 : } Phil