I have an application I'm developing that as a certain action has to send a POST request (with parameters) to an external web site (written in php, not under
my control). Is there a way I can generate this request and forward the browser to the new page from within a servlet/java code to emulate a http form post
any pointers gratefully received,
You could have your servlet build and POST the request to the external site. The response from that site could then be sent as a response to your client.
You wouldnt actually be 'forwarding' the browser to the external site, but POSTing data to it and then displaying the response the servlet receives. The problem with this approach is; if the external sites' response contains links/images with relative URL's in it, they wont work.
Thanks. I was hoping j2ee had some easy way of doing this, but I guess not.
I've got something to work, and I parse the respose to turn relative links/images
Do I have to send another response back to the external machine to say I received the cookie?
When you get the response from the external site, you should be able to read the cookie from the response header. I guess you could extract it and send it back with the next post.
Jakarta Commons HttpClient can sends HTTP POST requests to remote web servers..