How to use open uri or net/http class

Hi
   I am not able to access any http via Ruby program.I access internet
using proxy server. On runniong following program , it generates
error :
                            
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

require 'net/http'
require 'socket'
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]

  How to correct the code

Hi!

···

On 6/2/05, sujeet kumar <sujeetkr@gmail.com> wrote:

Hi
   I am not able to access any http via Ruby program.I access internet
using proxy server. On runniong following program , it generates
error :

The standard library documentation for HTTP provides some info. Check out:
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html

HTH!
Shajith

I tried to run the code of the site but it gives me error
   require 'net/http'

    proxy_addr = 'vsnlproxy.iitk.ac.in'
    proxy_port = 3128
            :
    Net::HTTP::Proxy(proxy_addr, proxy_port).start('www.example.com') {|http|
        # always connect to your.proxy.addr:8080
            :
    }
Error:
  c:/ruby/lib/ruby/1.8/uri/common.rb:432:in `split': bad URI(is not
URI?): (URI::
InvalidURIError)
        from c:/ruby/lib/ruby/1.8/uri/common.rb:481:in `parse'
        from url.rb:7
How to correct error ?

···

On 6/2/05, Shajith <demerzel@gmail.com> wrote:

Hi!

On 6/2/05, sujeet kumar <sujeetkr@gmail.com> wrote:
> Hi
> I am not able to access any http via Ruby program.I access internet
> using proxy server. On runniong following program , it generates
> error :
>

The standard library documentation for HTTP provides some info. Check out:
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html

HTH!
Shajith

Hi

···

On 6/2/05, sujeet kumar <sujeetkr@gmail.com> wrote:

I tried to run the code of the site but it gives me error
   require 'net/http'

    proxy_addr = 'vsnlproxy.iitk.ac.in'

Could you try with an "http://" prefixed to that?

Shajith