Professional Web Applications Themes

nuby problem with net/http - Ruby

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 ...

Sponsored Links
  1. #1

    Default nuby problem with net/http

    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 


    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
    Sponsored Links
    kris Guest

  2. #2

    Default Re: nuby problem with net/http

    Hello kris

    On Sat, 2004-02-07 at 11:24, kris wrote: 

    maybe yout try here
    h = Net::HTTP.new('www.pragmaticprogrammer.com',80,'p-addr', 'p-port')
    p-addr: the addresss of your proxy
    p-port: the port of your proxy
     
    >
    >
    > 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[/ref]


    bovi



    Daniel Guest

  3. #3

    Default Re: nuby problem with net/http

    In article <google.com>,
    kris <com> wrote: 

    Note that a couple of things have changed in Net::HTTP since the book came
    out, see changes below:
     

    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
     
    >
    >
    >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.[/ref]


    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
    Phil Guest

  4. #4

    Default Re: nuby problem with net/http

    Just want to thank you both for your quick responses...it works great now!

    thanks again
    K
    kris Guest

Similar Threads

  1. nuby: can't get an image via http
    By Guido in forum Ruby
    Replies: 6
    Last Post: February 2nd, 07:19 AM
  2. Replies: 4
    Last Post: January 3rd, 04:19 PM
  3. [Nuby] Object ID Lookup?
    By Jim in forum Ruby
    Replies: 5
    Last Post: December 16th, 01:29 AM
  4. nuby question re a method
    By Van in forum Ruby
    Replies: 3
    Last Post: December 11th, 01:37 PM
  5. HTTP 500 IIS 6.0 ASP problem
    By Mark Smithers in forum ASP
    Replies: 2
    Last Post: September 10th, 02:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139