Unable to run the code

P

Pradeepta Swain

Hi

I am trying to get a webpage using this code

require 'net/http'
Net::HTTP.start('www.rubyinside.com') do |http|
req = Net::HTTP::Get.new('/test.txt')
puts http.request(req).body
end

but it is giving error like

c:/apps/ruby/lib/ruby/1.8/net/http.rb:560:in `initialize': Bad file
descriptor - connect(2) (Errno::EBADF)
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
from c:/apps/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
from c:/apps/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:542:in `start'
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:440:in `start'
from ft.rb:15

what should I do to run the program . please help me out !

regards
pradeepta
 
S

s.ross

Hi

I am trying to get a webpage using this code

require 'net/http'
Net::HTTP.start('www.rubyinside.com') do |http|
req = Net::HTTP::Get.new('/test.txt')
puts http.request(req).body
end

req = http.get('/test.txt')

You have to use the http connection to make the GET request.
 
P

Pradeepta Swain

Steve said:
req = http.get('/test.txt')

You have to use the http connection to make the GET request.

Still getting the same errors ,i am using ruby 1.8.4 in windows XP
platform
please help me out !can You please send the full code 2 make a
connection
 
D

Dan Zwell

Pradeepta said:
Still getting the same errors ,i am using ruby 1.8.4 in windows XP
platform
please help me out !can You please send the full code 2 make a
connection

It works for me, as written, and I'm using ruby 1.8.6. I believe the API
for net/http changed a little between versions. I don't remember the
exact change, but try this variation:

require 'net/http'
Net::HTTP.start('www.rubyinside.com') do |http|
res = http.get('/test.txt')
puts res.body
end

Also try ".get2" instead of ".get". Good luck.
 
P

Pradeepta Swain

Thanx for ur reply ,but i just cannot run the code . Do i need ruby
1.8.6 ,or other set ups before running the code , I am using SciTE IDE
please reply
 
D

Dan Zwell

Pradeepta said:
Thanx for ur reply ,but i just cannot run the code . Do i need ruby
1.8.6 ,or other set ups before running the code , I am using SciTE IDE
.please reply

If nobody can reply that knows how to do this with ruby-1.8.5, then the
easiest thing would be to upgrade your installation of ruby. I can't say
for sure (because I'm not running Windows), but the script should work
with no modification in ruby-1.8.6. You should probably use the one
click installer, available at
http://rubyforge.org/frs/download.php/27227/ruby186-26_rc2.exe .

Good luck,
Dan
 
M

Matthew Harris

Pradeepta said:
Still getting the same errors ,i am using ruby 1.8.4 in windows XP
platform
please help me out !can You please send the full code 2 make a
connection
I've run your code on Ruby 1.8.6 on OS X, so this could either be a
net/http issue in 1.8.4, or a Windows issue, or a net/http issue with
Windows. Sorry I can't verify further.
 
S

Stefan Mahlitz

Pradeepta said:
Hi

I am trying to get a webpage using this code

require 'net/http'
Net::HTTP.start('www.rubyinside.com') do |http|
req = Net::HTTP::Get.new('/test.txt')
puts http.request(req).body
end

but it is giving error like

c:/apps/ruby/lib/ruby/1.8/net/http.rb:560:in `initialize': Bad file
descriptor - connect(2) (Errno::EBADF)
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
from c:/apps/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'
from c:/apps/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout'
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:542:in `start'
from c:/apps/ruby/lib/ruby/1.8/net/http.rb:440:in `start'
from ft.rb:15

what should I do to run the program . please help me out !

Do you have a firewall or proxy between your PC and the internet? I
remember that I had a problem like this (years ago). Just a wild guess.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top