0

I'm working on a Java application using Seam and I need to forward to a page on a different site, sending some POST data along with it. It needs to occur from the backend.

Any ideas how I can accomplish this?

EDIT: I don't merely need to receive the response - I need to actually direct the user to the new page.

NRaf
  • 7,407
  • 13
  • 52
  • 91
  • This may be helpful: http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests HttpClient is after all however less verbose. – BalusC Apr 18 '11 at 23:23
  • Are we talking about *forwarding* or *redirecting* the request? – Mike Baranczak Apr 18 '11 at 23:50
  • Yes, my mistake, it should have been redirecting. – NRaf Apr 18 '11 at 23:54
  • A redirect response from a server will always cause a browser to perform a separate GET request. However, if you're using a client you build (like with httpclient) you could program that client to perform POST requests on redirects instead of GET requests. – hooknc Apr 19 '11 at 05:38

1 Answers1

1

Take a look at HttpClient, you should be able to generate your POST request programatically from the backend, e.g:

PostMethod post = new PostMethod("http://myserver/page.jsp");
post.addParameter("parameter1", "value1");
post.addParameter("parameter2", "value2");

More details here:

http://weblogs.java.net/blog/2006/11/01/quick-intro-httpclient

Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150
  • Sorry, I probably wasn't as clear as I should've been. I need the page to get redirected. – NRaf Apr 18 '11 at 23:31
  • 1
    Does the target server use a [post and redirect](http://en.wikipedia.org/wiki/Post/Redirect/Get) pattern? If so, you might be able to do the post from the server and then tell the user's browser to handle the second half from the redirect URL that the target server responds with). Otherwise, your options are limited if you can't do anything on the client side with JavaScript. – Rob Tanzola Apr 18 '11 at 23:55