[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Unable to run the code

Pradeepta Swain

12/24/2007 6:26:00 AM

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
--
Posted via http://www.ruby-....

7 Answers

Steve Ross

12/24/2007 7:02:00 AM

0

On Dec 23, 2007, at 10:26 PM, Pradeepta Swain 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.

Pradeepta Swain

12/24/2007 8:19:00 AM

0

Steve Ross wrote:
> On Dec 23, 2007, at 10:26 PM, Pradeepta Swain 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
--
Posted via http://www.ruby-....

Dan Zwell

12/24/2007 8:42:00 AM

0

Pradeepta Swain wrote:
>>> 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

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 Swain

12/24/2007 9:02:00 AM

0

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
--
Posted via http://www.ruby-....

Dan Zwell

12/24/2007 9:24:00 AM

0

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

Good luck,
Dan

Matthew Harris

12/24/2007 10:32:00 AM

0

Pradeepta Swain wrote:
> Steve Ross wrote:
>
>> On Dec 23, 2007, at 10:26 PM, Pradeepta Swain 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
>
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.

--
Matthew Harris
http://matthew...


Stefan Mahlitz

12/24/2007 11:46:00 AM

0

Pradeepta Swain 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
>
> 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