1

In a JSP page, I need to do the following (this is psuedo-code):

//Attach new POST params to request
//Make the request go to a 3rd party URL

How do I do this?

The way we are solving this right now (is terrible):

//populate and generate an HTML form
//on window.load submit the HTML form (as a POST) to a 3rd party URL

We want all this to be done on the server side instead of having this JS hack

cmcculloh
  • 47,596
  • 40
  • 105
  • 130
  • You may want to re-title this. A redirect is *very* different from forwarding a request. Redirecting implies a specific response code from the server and the client sees that and re-issues the request to the new URL. Forwarding on behalf of the client, especially to an entirely different domain, is a different beast. – rfeak Jan 21 '11 at 21:18
  • OK. Thanks, I'll make it technically agnostic since I don't really know what the technical thing I want to do is called. I just care about what actually happens and don't want people to get hung up on terminology. – cmcculloh Jan 24 '11 at 14:05
  • Note that the both answers are suggesting a server side approach of proxying the request (the URL in browser address bar points to your own site) while your initial solution does basically a client side submit (the URL in browser address bar will point to the 3rd party URL). Proxying might not be what you want at all. – BalusC Jan 24 '11 at 15:05
  • You are correct, I don't really want proxying. I would prefer the user ended up at the 3rd party URL, I just want to be able to add a couple post vars on their way out, but the post vars have to be generated by a page that needs the info they place on the page they are leaving. – cmcculloh Jan 25 '11 at 15:58

3 Answers3

2

You can use URLConnection to make POST request, here is an example

jmj
  • 237,923
  • 42
  • 401
  • 438
2

There are many ways to send a HTTP POST. I recommend a use of apache HttpClient library.

Here is the previous question and answers on Stack Overflow. The question was for Andriod but should work perfectly with Java.

Another method is to use URLConnection class. There was an answer posted by me on that question.

Community
  • 1
  • 1
gigadot
  • 8,879
  • 7
  • 35
  • 51
0

There is no way to do this in Java. You would need some sort of proxy server or apache re-write rule or something like that. Java is not the right place to do this.

cmcculloh
  • 47,596
  • 40
  • 105
  • 130