T
tsuraan
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 =3D Net::HTTP.post_form(URI.parse('http://www.example.com/search.cg=
i'),
{'q'=3D>'ruby', 'max'=3D>'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 =3D URI.parse('http://www.example.com/todo.cgi')
req =3D Net::HTTP:ost.new(url.path)
req.set_form_data({'from'=3D>'2005-01-01', 'to'=3D>'2005-03-31'}, ';')
res =3D 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?
snippet for getting data from a server using HTTP POST:
require 'net/http'
require 'uri'
res =3D Net::HTTP.post_form(URI.parse('http://www.example.com/search.cg=
i'),
{'q'=3D>'ruby', 'max'=3D>'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 =3D URI.parse('http://www.example.com/todo.cgi')
req =3D Net::HTTP:ost.new(url.path)
req.set_form_data({'from'=3D>'2005-01-01', 'to'=3D>'2005-03-31'}, ';')
res =3D 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?