Forum: Ruby Net::HTTP.post_form method undefined?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fe57662c550fb3cce44c398ddf2dd706?d=identicon&s=25 itsme213 (Guest)
on 2006-01-04 07:38
(Received via mailing list)
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!
669b7046f02e5dfc4bda4421f1069731?d=identicon&s=25 Alex Fenton (Guest)
on 2006-01-04 10:45
(Received via mailing list)
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
31af45939fec7e3c4ed8a798c0bd9b1a?d=identicon&s=25 Matthew Smillie (Guest)
on 2006-01-04 11:30
(Received via mailing list)
On Jan 4, 2006, at 9:42, Alex Fenton wrote:

> doesn't exist in ruby 1.8. Annoying huh?
It exists in 1.8.3, it would seem:

[Prospero:~] matt% ruby -v
ruby 1.8.3 (2005-09-21) [powerpc-darwin8.3.0]
[Prospero:~] matt% ruby
require 'net/http'
puts Net::HTTP.methods.include?("post_form")
true

I've used it with no problems at all, in the same basic format as the
original poster.

matthew smillie.
Fe57662c550fb3cce44c398ddf2dd706?d=identicon&s=25 itsme213 (Guest)
on 2006-01-04 18:12
(Received via mailing list)
Thanks Alex, that was it, I'm on 1.8.3.


"Alex Fenton" <alex@deleteme.pressure.to> wrote in message
news:2KKdnYKLbIafBSbeRVnyig@pipex.net...
This topic is locked and can not be replied to.