Posted By:
Christopher_Pickslay
Posted On:
Tuesday, August 7, 2001 10:31 PM
1) Get a
HttpURLConneciton to the servlet using:
String urlString = "http://your-host/your-servlet";
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) (url.openConnection());
2) Set the request method to POST:
conn.setRequestMethod("POST");
3) Create your POST data (POST data looks just like GET data):
String postData;
postData += "field1";
postData += "=";
postData += URLEncoder.encode("value for field1");
postData += "&";
postData += "field2";
postData += "=";
postData += URLEncoder.encode("value for field2");
3) Write your POST data to your
HttpURLConnection's
OutputStream:
PrintWriter out = new PrintWriter(conn.getOutputStream);
out.print(postData);
out.close();
4) Get your
HttpURLConnection's
InputStream to read the result:
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream));