views:

18

answers:

2

Is there a ruby method to POST form data encoded in "x-www-form-urlencoded" as specified here? http://www.w3.org/MarkUp/html-spec/html-spec_8.html

I am aware of Net::HTTP.post_form, but because I have several values to post which share the same name I can't use a hash, which is required by that method.

To clarify, I have a string of the form "value1=x&value1=y&value1=z&value2=a&value3=b" and I want to be able to POST it to another page. How can I do this?

A: 

Are you able to have a hash value which is an Array? I think that this is the way parameters with the same names are usually handled.

Collin
I have tried that actually, but I may have done it incorrectly as I am new to Ruby. Could you provide a piece of example code please?
bsirang
When I try using a hash like this: myHash = {key => ["value1","value2","value3"]} It seems to post the value as "value1value2value3". Am I doing something wrong?
bsirang
A: 

I think internally the params object is a parsed version of the actual raw post body in the http request. All post data is posted the same way (as raw post data), but the params hash in ActionController has already parsed this into an easy-to-use hash. If you actually need the raw post data from a form, you can access it through the raw_post method of the request object itself.

The ActionController::Request.raw_post documentation here is for rails3, but has been available since at least 2.3.8 (the only 2.3.x version I checked). I think it most likely has been available longer than that.

In a controller, try self.request.raw_post to get the raw post data as a string.

Brett Bender
I'm not trying to obtain the data POSTed to a RoR page. I'm trying to POST data to an external page.
bsirang