[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Net::HTTP.post_form method undefined?

Its Me

1/4/2006 6:35:00 AM

I'm trying to do a POST using net/http.

When I do:

r = Net::HTTP.post_form(u,{'volumectrl'=>'-20'})

I get:

NoMethodError: undefined method `post_form' for Net::HTTP:Class
from (irb):5

What am I doing wrong?

Thanks!


3 Answers

Alex Fenton

1/4/2006 9:40:00 AM

0

itsme213 wrote:
> I'm trying to do a POST using net/http.
>
> r = Net::HTTP.post_form(u,{'volumectrl'=>'-20'})
>
> I get:
>
> NoMethodError: undefined method `post_form' for Net::HTTP:Class
> from (irb):5

What ruby version are you running? I ran into this same problem last week, and it was because the standard stdlib documentation (on ruby-doc) refers to ruby 1.9, where the post_form method exists. It doesn't exist in ruby 1.8. Annoying huh?

Try something like:

Net::HTTP.start('www.foo.com', 80) do | http |
response = http.post('/cgi-bin/foo.cgi', encoded_post)
end

Note that you'll need to manually turn your hash into a URI-encoded string. Look at URI.encode() in the stdlib.

alex

Its Me

1/4/2006 3:43:00 PM

0

Thanks Alex, that was it, I'm on 1.8.3.


"Alex Fenton" <alex@deleteme.pressure.to> wrote in message
news:2KKdnYKLbIafBSbeRVnyig@pipex.net...
> itsme213 wrote:
>> I'm trying to do a POST using net/http.
>>
>> r = Net::HTTP.post_form(u,{'volumectrl'=>'-20'})
>>
>> I get:
>>
>> NoMethodError: undefined method `post_form' for Net::HTTP:Class
>> from (irb):5
>
> What ruby version are you running? I ran into this same problem last week,
> and it was because the standard stdlib documentation (on ruby-doc) refers
> to ruby 1.9, where the post_form method exists. It doesn't exist in ruby
> 1.8. Annoying huh?
>
> Try something like:
>
> Net::HTTP.start('www.foo.com', 80) do | http |
> response = http.post('/cgi-bin/foo.cgi', encoded_post)
> end
>
> Note that you'll need to manually turn your hash into a URI-encoded
> string. Look at URI.encode() in the stdlib.
>
> alex


mathew

1/15/2006 10:15:00 PM

0

Alex Fenton wrote:
> What ruby version are you running? I ran into this same problem last
> week, and it was because the standard stdlib documentation (on ruby-doc)
> refers to ruby 1.9, where the post_form method exists. It doesn't exist
> in ruby 1.8. Annoying huh?

It does exist in Ruby 1.8, you just need to upgrade to the current
version of Ruby 1.8, version 1.8.4.


mathew
--
<URL:http://www.pobox.com/...
My parents went to the lost kingdom of Hyrule
and all I got was this lousy triforce.