Is it possible to "chain" a request from a servlet to an ASP page so that the invoking browser sees the ASP results? I need to front-end a request in my servlet and pass the call on to an ASP page that is not under my control. The HTTP form request for the ASP page looks something like this:
- Posted by: Kevin Collins
- Posted on: February 28 2002 11:57 EST
<form NAME="gateway" METHOD="POST" ACTION="http://some_other_server.com/ASP_Page.asp">
<input TYPE="HIDDEN" NAME="SecurityFlag" VALUE="mycompany">
<input type="HIDDEN" NAME="UserName" SIZE="16" MAXLENGTH="20" VALUE="my_UID">
<input TYPE="HIDDEN" NAME="Password" SIZE="16" MAXLENGTH="20" VALUE="my_pwd">
How do I encode that into a URL object (assuming that's what I need to use)?
Thanks in advance,
Since you probably dont want to pass the user/pwd in the URL, you can open a POST URLConnection and send the data over the connection in name/pair values.
HttpURLConnection server = (HttpURLConnection)new URL("http://some_other_server.com/ASP_Page.asp").openConnection();
PrintWriter out = new PrintWriter(server.getOutputStream());
//Then read the InputStream if you need to get the results from the ASP....
Hope this helps
Thanks Weston -- that does help. However, what I really want is for the response from the ASP page to return to the original client browser, because once I pass the login info off, I'm done and out of the picture. From then on it's a conversation between the browser and the application that is hosting that first ASP page.
It will. You servlet has the response output stream (response.getWriter()), which you can use to send the response from the ASP page to the original client.
Actually since your invoking the ASP programatically, the data could be sent in the URL as a GET request. I originally pictured the browser showing the data in the URL...but obviously thats not the case.
Now of course anyone watching network traffic could see the data either way.