Hi,
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
request?
any pointers gratefully received,
Jonny
-
programatic POST request from servlet? (4 messages)
- Posted by: Jonny Wray
- Posted on: April 15 2003 17:18 EDT
Threaded Messages (4)
- programatic POST request from servlet? by Web Master on April 17 2003 15:01 EDT
- programatic POST request from servlet? by Jonny Wray on April 17 2003 19:29 EDT
- programatic POST request from servlet? by Web Master on April 18 2003 07:59 EDT
- programatic POST request from servlet? by Jonny Wray on April 17 2003 19:29 EDT
- Jakarta Commons HttpClient by Sean Sullivan on June 03 2003 19:37 EDT
-
programatic POST request from servlet?[ Go to top ]
- Posted by: Web Master
- Posted on: April 17 2003 15:01 EDT
- in response to Jonny Wray
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. -
programatic POST request from servlet?[ Go to top ]
- Posted by: Jonny Wray
- Posted on: April 17 2003 19:29 EDT
- in response to Web Master
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
into absolute pointing to the external site. All works, except a problem with cookies. The external site I'm going to uses cookies to track user sessions. If I turn off cookies on my browser (going directly to the site) I cannot add things to the "cart". I get the same response from my servlet code - as if I'm not receiving cookies, although I am.
Do I have to send another response back to the external machine to say I received the cookie?
thanks,
Jonny -
programatic POST request from servlet?[ Go to top ]
- Posted by: Web Master
- Posted on: April 18 2003 07:59 EDT
- in response to Jonny Wray
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[ Go to top ]
- Posted by: Sean Sullivan
- Posted on: June 03 2003 19:37 EDT
- in response to Jonny Wray
Jakarta Commons HttpClient can sends HTTP POST requests to remote web servers..
http://jakarta.apache.org/