tags:

views:

43

answers:

2
require 'net/http'
require 'uri'
Net::HTTP.get_print URI.parse('http://www.example.com/index.html')

when i tried to run this programm i getting error like this why??

c:/ruby/lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: no address associated with hostname. (SocketError)
    from c:/ruby/lib/ruby/1.8/net/http.rb:560:in `open'
    from c:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
    from c:/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
    from c:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
    from c:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
    from c:/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
    from c:/ruby/lib/ruby/1.8/net/http.rb:542:in `start'
    from c:/ruby/lib/ruby/1.8/net/http.rb:379:in `get_response'
    from c:/ruby/lib/ruby/1.8/net/http.rb:337:in `get_print'
    from ruby2.rb:3
A: 

the code looks correct and runs as expected on my machine - are you sure that dns is set up correctly on your machine? do you need a proxy to make web-calls? can you open the url in a browser?

Nikolaus Gradwohl
no but i can open a particular url in brower for that url im tring this code but its not working
Amit singh tomar
nd what should be expected o/p of this code
Amit singh tomar
the html-sourcecode of the referenced site gets printed on the console.
Nikolaus Gradwohl
Nikolaus i do n't have access to net but one particular url is there that i can open i put that url in my code it's not workingtell me soultion wht should i do now
Amit singh tomar
try to access the server by ipadress instead of the hostname to test if your code breaks at the nameserver resolution - if this works make sure the nameservers are configured corretly on your machine or enter the ip/hostname pair into the hosts file
Nikolaus Gradwohl
sorry but i didn't get you ip/hostname pair into the hosts filewhat does that mean
Amit singh tomar
this is how your computer translates hostnames to ip adresses
Nikolaus Gradwohl
c:/ruby/lib/ruby/1.8/net/http.rb:560:in `initialize': Bad file descriptor - connect(2) (Errno::EBADF)i tried with ipaddress but i got this above plus all error before
Amit singh tomar
how do i enter this ip/hostname pair into the hosts file means and file file means where i put this code??
Amit singh tomar
you don't do that in your code, its how your computer is configurated
Nikolaus Gradwohl
now i what should i do i really need to rub this code what to do
Amit singh tomar
anything else i can do???i also tried with ip adress but its giving error bad file descriptor
Amit singh tomar
sorry i'm out of ideas - maybe try it on another computer
Nikolaus Gradwohl
A: 

I don't, I get a response. Were you online at the time?

Amadan
Amadan i m using particular url that i can open for that i am tring this code but its not working
Amit singh tomar