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.
Neil Middleton 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 -- Posted via http://www.ruby-forum.com/.
7stud -- wrote:> I should add that I want to redirect the userwhoops. -- Posted via http://www.ruby-forum.com/.
> 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
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 On May 1, 2:42 pm, Olek <olek.janiszew...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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