From: Robert Klemme Date: 2005-11-12T01:07: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 > > 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?