From: James Britt Date: 2005-11-12T01:08:14+09:00 Subject: Re: net/http broken? tsuraan wrote: > The documentation for net/http on ruby-doc.org gives the following > snippet for getting data from a server using HTTP POST: > > require 'net/http' > require 'uri' > > res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'), > {'q'=>'ruby', 'max'=>'50'}) > puts res.body > > 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 = 'Doodle!' Net::HTTP.start( uri, port) { |http| results = http.post( page, data ) } James -- http://www.ruby-doc.org - Ruby Help & Documentation http://www.artima.com/rubycs/ - Ruby Code & Style: Writers wanted http://www.rubystuff.com - The Ruby Store for Ruby Stuff http://www.jamesbritt.com - Playing with Better Toys http://www.30secondrule.com - Building Better Tools