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