Unable to run the code

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:inconnect’
from c:/apps/ruby/lib/ruby/1.8/timeout.rb:48:in timeout' from c:/apps/ruby/lib/ruby/1.8/timeout.rb:76:intimeout’
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:indo_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:instart’
from ft.rb:15

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

                                                    regards
                                                    pradeepta

On Dec 23, 2007, at 10:26 PM, Pradeepta S. wrote:

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.

Steve R. wrote:

On Dec 23, 2007, at 10:26 PM, Pradeepta S. wrote:

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.

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

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

Pradeepta S. wrote:

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.

Pradeepta S. wrote:

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

Pradeepta S. wrote:

but it is giving error like
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

Pradeepta S. wrote:

Net::HTTP.start(‘www.rubyinside.com’) do |http|
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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs