Forum: Ruby on Rails Posting a form from Rails programatically

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Neil M. (Guest)
on 2009-04-30 23:23
(Received via mailing list)
How would I go about creating and posting a form POST request from
inside some Rails code?
The use case I have is that I have received a form request, and I
would like to forward this request on to a third party with my
parameters intact.

I should add that I want to redirect the user out to the third party
with the form too.  Essentially I want it to appear to the user that
they've submitted the form to the third party directly.
7stud -. (Guest)
on 2009-05-01 00:18
Neil M. wrote:
> How would I go about creating and posting a form POST request from
> inside some Rails code?
> The use case I have is that I have received a form request, and I
> would like to forward this request on to a third party with my
> parameters intact.
>
> I should add that I want to redirect the user out to the third party
> with the form too.  Essentially I want it to appear to the user that
> they've submitted the form to the third party directly.

Check out mechanize:

http://mechanize.rubyforge.org/mechanize/GUIDE_rdoc.html
7stud -. (Guest)
on 2009-05-01 00:19
7stud -- wrote:
> I should add that I want to redirect the user

whoops.
Olek (Guest)
on 2009-05-01 17:43
(Received via mailing list)
> I should add that I want to redirect the user out to the third party
> with the form too.  Essentially I want it to appear to the user that
> they've submitted the form to the third party directly.

You can either use an HTTP 307 response (http://www.w3.org/Protocols/
rfc2616/rfc2616-sec10.html#sec10.3.8) which, according to the
standard, should re-send the original request to the given location
(keeping the original method and data), but browsers require
confirmation from the user (most browsers - an unfriendly dialog),
some browser-specific quirks may occur as well. Except from this,
that's the 'standard' method for your use case.

You can also use any Ruby HTTP client to send the request from your
server, wait for the response, and, basing on it, send your response
(maybe a redirect) to the client. This solution is more complicated to
implement, and if it's a non-trivial third party form, some issues
with cookies/sessions may appear.

Keep us updated on your progress.

--
Bye,
Olek
Neil M. (Guest)
on 2009-05-01 18:15
(Received via mailing list)
I've tried a 307, which seems to work with Firefox (with a warning, as
you say), but Safari (4) seems to miss the re-post.  I've not checked
IE, as I've not got a copy to hand.

Neil
This topic is locked and can not be replied to.