# Passing POST params from one rhtml to another

**URL:** <https://www.ruby-forum.com/t/passing-post-params-from-one-rhtml-to-another/65114>\
**Category:** Ruby\
**Created:** [February 9, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/passing-post-params-from-one-rhtml-to-another/65114 "2006-02-09T18:04:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 9, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/passing-post-params-from-one-rhtml-to-another/65114/1 "2006-02-09T18:04:13Z")

</div>

Greetings everyone. I am faced with a rather tricky problem. I have  
mod\_ruby/eRuby going on Apache, and have the following situation:

I have an outer rhtml file which, using the open-uri library, opens up a  
remote rhtml file from one of my other servers to dump the contents  
inside  
the outer rhtml. In other words, I have 1 rhtml wrapping another one  
from  
my other remote site.

Unfortunately, I also need to pass POST data from a form to the inner  
rhtml. So, the outer rhtml recieves the POST data and can be used using  
CGI.new, but I don’t know how to pass the same post data to the inner  
rhtml  
file. I was doing this previously by simply doing some URL rewriting  
(?blah=1&foo=2, etc), but that doesn’t work anymore because one of the  
form  
field values contains lots of spaces and other erroneous characters that  
make Apache barf:

request failed: erroneous characters after protocol string:

Does anyone know of anyway to POST the data to the inner rhtml file  
instead  
of passing it along inside the URL? Unfortunately, directly invoking  
ERB  
will not work as the file is not locally available (hence the loading up  
via  
open-uri). I’ve also tried executing url\_encode from the ERB library to  
encode the URL into readable form, but the CGI barfs on my inner rhtml  
because instead of CGI.params looking like this:

{ “foo”=\>1} it looks like this {“foo=1”=\>nil }

(the encoded form of the URL: url\_encode( “?foo=1”) gives “foo%3d1”)

Any suggestions? Thanks.

Matt

p.s. Y

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 9, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/passing-post-params-from-one-rhtml-to-another/65114/2 "2006-02-09T18:34:05Z")

</div>

Belorion wrote:

> CGI.new, but I don’t know how to pass the same post data to the inner rhtml  
> file.

Can you use open-uri to send an HTTP POST request?

(from: [http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/](http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/))

open(“[Ruby Programming Language](http://www.ruby-lang.org/en/)”,  
“User-Agent” =\> “Ruby/#{RUBY\_VERSION}”,  
“From” =\> “removed\_email\_address@domain.invalid”,  
“Referer” =\> “[http://www.ruby-lang.org/](http://www.ruby-lang.org/)”) {|f|  
…  
}

Could the headers hold the post metadata?

“Content-Length” =\> some\_base64\_encoded\_stuff.size  
“Content-Type” =\> “application/x-www-form-urlencoded”

I believe the some\_base64\_encoded\_stuff part has to go in the body of  
the request, though. I don’t know if open-uri provides for that.

If not, then use a library than can do a POST, such as net/http.

–  
James B.

“A language that doesn’t affect the way you think about programming is  
not worth knowing.”

- A. Perlis
