Hello,
This is true and I actuallly tried this but what happens in the
servlet will do the post as it should but will NOT forward
the user to the resulting page. Even if you went ahead and redirected on
to the external site after the post, you still will not have the posted data.
I think javascript may come in handy here but have to deal with cross platform issues.
Craig R. McClanahan wrote:
> Ellecer Valencia wrote:
>
>
>> haven't found a way to get a servlet to to a POST to an external site.
>>
>> i've only seen code for a java APPLET to do a post, but not a servlet...
>>
>
>
> A servlet can send POST requests to a remote site using exactly the same logic that
>an Applet
> can -- using the java.net.HttpURLConnection class. Leaving out error handling for
>clarity, it
> goes something like this:
>
> URL url = new URL("http://localhost:8080/myapp/myservlet");
> URLConnection uconn = url.openConnection();
> HttpURLConnection hconn = (HttpURLConnection) uconn;
> hconn.setRequestMethod("POST");
> hconn.setContentType("application/x-www-form-urlencoded");
> hconn.setDoOutput(true);
> hconn.connect();
> OutputStream os = hconn.getOutputStream();
> ... write the POST data, suitably encoded ...
>
> Craig McClanahan
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
--
Vincent Stoessel [EMAIL PROTECTED]
Internet Applications Engineer
IDEV http://www.idev.com
V: 301 495 7345 x129
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html