The problem with this is that in ruby 1.8.2 on both my OSX box and my
FreeBSD computer, Net::HTTP does not have a post_form defined. So,
that example doesn't work. Another way of doing the same idea, given
by ruby-doc.org, is:
url = URI.parse('http://www.example.com/todo.cgi')
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
res = Net::HTTP.new(url.host, url.port).start { http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
end
This has the problem that req has no set_form_data method. So, does
anyone know what's going wrong? Is it possible to use the ruby
standard libraries to post data to a server?
The problem with this is that in ruby 1.8.2 on both my OSX box and my
FreeBSD computer, Net::HTTP does not have a post_form defined. So,
that example doesn't work. Another way of doing the same idea, given
by ruby-doc.org, is:
url = URI.parse('http://www.example.com/todo.cgi'\)
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
res = Net::HTTP.new(url.host, url.port).start { http.request(req)
} case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
end
This has the problem that req has no set_form_data method. So, does
anyone know what's going wrong? Is it possible to use the ruby
standard libraries to post data to a server?
The problem with this is that in ruby 1.8.2 on both my OSX box and my
FreeBSD computer, Net::HTTP does not have a post_form defined.
Hm, 1.8.3 has it:
17:02:52 [~]: ruby -r net/http -e 'p RUBY_VERSION; p
Net::HTTP.public_methods.grep /post/i'
-e:1: warning: parenthesize argument(s) for future version
"1.8.3"
["post_form"]
This is on cygwin. I wouldn't assume that post_form was removed in 1.8.2
and added in 1.8.3. Are you sure the method is not present? (You can
test with the same code snippet.)
The problem with this is that in ruby 1.8.2 on both my OSX box and my
FreeBSD computer, Net::HTTP does not have a post_form defined. So,
that example doesn't work. Another way of doing the same idea, given
by ruby-doc.org, is:
url = URI.parse('http://www.example.com/todo.cgi'\)
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
res = Net::HTTP.new(url.host, url.port).start { http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
end
Seems the docs are wrong. I had the same problem not too long ago.
Here's an example of what works for me:
require 'net/http'
# post some data to uri:port/page
uri = 'www.example.com'
port = 80
page = '/RPC/foo'
data = '<foo><bar>Doodle!</bar></foo>'
17:02:52 [~]: ruby -r net/http -e 'p RUBY_VERSION; p
Net::HTTP.public_methods.grep /post/i'
-e:1: warning: parenthesize argument(s) for future version
"1.8.3"
["post_form"]
This is on cygwin. I wouldn't assume that post_form was removed in 1.8.2
and added in 1.8.3. Are you sure the method is not present? (You can
test with the same code snippet.)
Ah. That explains my problem using the Windows installer version. There has been no 1.8.3 release, for assorted reasons, and I forgot that I'm therefore not running the latest Ruby.
So my suggestion is a 1.8.2 bit of code.
I believe Curt will release a 1.8.4 Windows installer version when Matz releases that version of Ruby around Christmas.
The problem with this is that in ruby 1.8.2 on both my OSX box and my
FreeBSD computer, Net::HTTP does not have a post_form defined.
>
Seems the docs are wrong. I had the same problem not too long ago.
The docs on ruby-doc.org are taken from the CVS head. The documentation for net/http (which I believe I was the last person to update) reflects the version of net/http in CVS at the time, which is the version that became part of the Ruby 1.8.4 release.
So the docs are (probably)(*) right, you just need to either use a more recent Ruby, or use an older version of the docs.
mathew
[ (*) I say "probably" because I didn't check the specific example code
for HTTP post already given in the sources; I just checked the code
examples I added. ]
···
--
<URL:http://www.pobox.com/~meta/>
My parents went to the lost kingdom of Hyrule
and all I got was this lousy triforce.
Oh my god this is hilarious! I just had to deal with this exact problem!
It's definitely a 1.8.2/1.8.3 thing... that post_form method doesn't exist
in 1.8.2.
Take care,
···
On 11/11/05, mathew <meta@pobox.com> wrote:
James Britt wrote:
>tsuraan wrote:
>> The problem with this is that in ruby 1.8.2 on both my OSX box and my
>> FreeBSD computer, Net::HTTP does not have a post_form defined.
>
> Seems the docs are wrong. I had the same problem not too long ago.
The docs on ruby-doc.org <http://ruby-doc.org> are taken from the CVS
head. The documentation
for net/http (which I believe I was the last person to update) reflects
the version of net/http in CVS at the time, which is the version that
became part of the Ruby 1.8.4 release.
So the docs are (probably)(*) right, you just need to either use a more
recent Ruby, or use an older version of the docs.
mathew
[ (*) I say "probably" because I didn't check the specific example code
for HTTP post already given in the sources; I just checked the code
examples I added. ]
--
<URL:http://www.pobox.com/~meta/>
My parents went to the lost kingdom of Hyrule
and all I got was this lousy triforce.