How do I post to a form (http) in Ruby 1.8.2?


Hi all,

How do I do the equivalent of Net::HTTP.post_form() in Ruby 1.8.2? (This
method was not implemented until 1.8.3).

This might seem like a strange question but bear with me.

Though our production server is running Ruby 1.8.4, our development
machines are Macs using Locomotive (which is a self-contained Ruby/Rails
environment). I have been told by one of the lead Locomotive developers
that it is virtually impossible to upgrade the version of Ruby inside
Locomotive, that I should wait for the next version which will use a
more current version of Ruby.

So my question is, until then, how would I make the following code
fragment, which works in 1.8.3+, work in 1.8.2?

require ‘net/http’
require ‘uri’

parms = {:client=>“safari”, :rls=>“en”, :q => “myquery”,
:ie => “UTF-8”, :oe => “UTF-8”}
url = “

res = Net::HTTP.post_form(URI.parse(url), parms)

print res.body

(By “work”, I mean, getting something back from the server–in this
particular case the server may return an error, but at least the post

It has been suggested that I extend Ruby to implement this method. I
gave that a try and it didn’t seem too easy, as post_form in turn
depends on other methods that don’t exist in 1.8.2. But I am a total
newbie at extending Ruby so it could be I missed something

I couldn’t get the examples of request_post to work either.

At this point I don’t care what approach I use, I just want to be able
to post to a form on an http server in Ruby 1.8.2. Any idea what would
be the quickest way to do that?