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

D

Dan Tenenbaum

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", :eek:e => "UTF-8"}
url = "http://www.google.com/search"

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

print res.body
print

(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
succeeded.)

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?
Thanks
 

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

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top