Net::HTTP and post_form

J

Joel VanderWerf

I expected this to work (since the #post_form method is documented), but
the method is not found:

require 'net/http'

Net::HTTP.start('127.0.0.1', 4567) do |http|
http.post_form('/foo', "bar" => "baz")
end

Here's the error:

http-post-bug.rb:4: undefined method `post_form' for #<Net::HTTP
127.0.0.1:4567 open=false> (NoMethodError)
from /usr/local/lib/ruby/1.8/net/http.rb:543:in `start'
from /usr/local/lib/ruby/1.8/net/http.rb:440:in `start'
from http-post-bug.rb:3


Why isn't post_form usable in the block form? I'm using the block form
because it's actually going thru a proxy.

I can do it myself by creating the request manually:

req = Net::HTTP::post.new(path)
req.form_data = params
Net::HTTP.new('127.0.0.1', 4567).start {|http|
http.request(req)
}

but it's kind of disappointing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top