Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Ruby doesn't work correctly
Patrick
6/6/2006 1:58:00 PM
Hi,
Im a beginner in Ruby, but with skills in other programming languages.
I tried to execute the following code:
require 'net/http'
require 'uri'
#1: Simple POST
res =
Net::HTTP.post_form(URI.parse('
http://www.example.com/searc...
),
{'q'=>'ruby', 'max'=>'50'})
puts res.body
I got the code from
http://www.ruby-doc.o...
-> net/http. Of
course, I replaced the Site ("www.example.com...") with my site
(because i want to send informations to a php-programm).
But the console does the following output:
mypath/ruby/lib/ruby/1.8/net/protocol.rb:175:in `write': Invalid
argument (Errno::EI
NVAL)
from mypath/ruby/lib/ruby/1.8/net/protocol.rb:175:in `write0'
from mypath/ruby/lib/ruby/1.8/net/protocol.rb:151:in `write'
from mypath/ruby/lib/ruby/1.8/net/protocol.rb:166:in `writing'
from mypath/ruby/lib/ruby/1.8/net/protocol.rb:150:in `write'
from mypath/ruby/lib/ruby/1.8/net/http.rb:1542:in
`write_header'
from mypath/ruby/lib/ruby/1.8/net/http.rb:1513:in
`send_request_with_body'
from mypath/ruby/lib/ruby/1.8/net/http.rb:1496:in `exec'
from mypath/ruby/lib/ruby/1.8/net/http.rb:1044:in `request'
from mypath/ruby/lib/ruby/1.8/net/http.rb:405:in `post_form'
from mypath/ruby/lib/ruby/1.8/net/http.rb:545:in `start'
from mypath/ruby/lib/ruby/1.8/net/http.rb:404:in `post_form'
from mypath/php.rb:5
Line 5 is: res =
Net::HTTP.post_form(URI.parse('
http://www.example.com/searc...
),
{'q'=>'ruby', 'max'=>'50'})
I thought my ruby is maybe damaged, so i deleted it, and installed it
new. But i get always the same error.
I hope anyone would be so kind and can help me.
Thank you,
Patrick
2 Answers
Jay
6/6/2006 10:56:00 PM
0
Patrick,
I'm even more of a beginner in Ruby than you are, but I'm wondering if
you cant put a breakpoint in the ruby code and debug it. I'm using
ActiveState Komodo, which allows for Ruby debugging, and the file you
referenced, "protocol.rb", is included when you install ruby.
Patrick wrote:
> Hi,
>
> Im a beginner in Ruby, but with skills in other programming languages.
>
> I tried to execute the following code:
>
> require 'net/http'
> require 'uri'
>
> #1: Simple POST
> res =
> Net::HTTP.post_form(URI.parse('
http://www.example.com/searc...
),
> {'q'=>'ruby', 'max'=>'50'})
> puts res.body
>
> I got the code from
http://www.ruby-doc.o...
-> net/http. Of
> course, I replaced the Site ("www.example.com...") with my site
> (because i want to send informations to a php-programm).
>
> But the console does the following output:
>
> mypath/ruby/lib/ruby/1.8/net/protocol.rb:175:in `write': Invalid
> argument (Errno::EI
> NVAL)
> from mypath/ruby/lib/ruby/1.8/net/protocol.rb:175:in `write0'
> from mypath/ruby/lib/ruby/1.8/net/protocol.rb:151:in `write'
> from mypath/ruby/lib/ruby/1.8/net/protocol.rb:166:in `writing'
> from mypath/ruby/lib/ruby/1.8/net/protocol.rb:150:in `write'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:1542:in
> `write_header'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:1513:in
> `send_request_with_body'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:1496:in `exec'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:1044:in `request'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:405:in `post_form'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:545:in `start'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:404:in `post_form'
> from mypath/php.rb:5
>
> Line 5 is: res =
> Net::HTTP.post_form(URI.parse('
http://www.example.com/searc...
),
> {'q'=>'ruby', 'max'=>'50'})
>
> I thought my ruby is maybe damaged, so i deleted it, and installed it
> new. But i get always the same error.
>
> I hope anyone would be so kind and can help me.
>
> Thank you,
>
> Patrick
Tim Hoolihan
6/7/2006 1:30:00 PM
0
The second version of the pickaxe book (p.699) shows doing your example
like the following:
require 'net/http'
Net::HTTP.start('www.example.com') do |http|
res = http.post("/search.cgi","q=ruby&max=50")
puts res.body
end
When I tried this way on a page that receives a post, it did not seem to
receive the post value, but there were no ruby errors, so I tend to
think that I am just posting the wrong info or using the wrong syntax in
my second argument ("q=ruby..."). Anyway, I would play around with that.
-Tim
Patrick wrote:
> Hi,
>
> Im a beginner in Ruby, but with skills in other programming languages.
>
> I tried to execute the following code:
>
> require 'net/http'
> require 'uri'
>
> #1: Simple POST
> res =
> Net::HTTP.post_form(URI.parse('
http://www.example.com/searc...
),
> {'q'=>'ruby', 'max'=>'50'})
> puts res.body
>
> I got the code from
http://www.ruby-doc.o...
-> net/http. Of
> course, I replaced the Site ("www.example.com...") with my site
> (because i want to send informations to a php-programm).
>
> But the console does the following output:
>
> mypath/ruby/lib/ruby/1.8/net/protocol.rb:175:in `write': Invalid
> argument (Errno::EI
> NVAL)
> from mypath/ruby/lib/ruby/1.8/net/protocol.rb:175:in `write0'
> from mypath/ruby/lib/ruby/1.8/net/protocol.rb:151:in `write'
> from mypath/ruby/lib/ruby/1.8/net/protocol.rb:166:in `writing'
> from mypath/ruby/lib/ruby/1.8/net/protocol.rb:150:in `write'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:1542:in
> `write_header'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:1513:in
> `send_request_with_body'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:1496:in `exec'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:1044:in `request'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:405:in `post_form'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:545:in `start'
> from mypath/ruby/lib/ruby/1.8/net/http.rb:404:in `post_form'
> from mypath/php.rb:5
>
> Line 5 is: res =
> Net::HTTP.post_form(URI.parse('
http://www.example.com/searc...
),
> {'q'=>'ruby', 'max'=>'50'})
>
> I thought my ruby is maybe damaged, so i deleted it, and installed it
> new. But i get always the same error.
>
> I hope anyone would be so kind and can help me.
>
> Thank you,
>
> Patrick
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Ruby doesn't work correctly
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password