Posted By:
Michael_Wax
Posted On:
Saturday, April 7, 2001 04:12 PM
Using something like the following should work. What this does is to create a URLConnection, write out the POST parameters, and then read in the reply from the remote server. Note that the parameter values should be URL encoded in case they contain any special characters.
//get connection and setup for post
URL url = new URL("http://www.whatever.com");
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput (true);
connection.setUseCaches (false);
//write out post parameters
DataOutputStream outputStream = new DataOutputStream (connection.getOutputStream ());
String params = "first=" + URLEncoder.encode("value1") + ...;
outputStream.writeBytes (params);
outputStream.flush ();
outputStream.close ();
//read from the server
DataInputStream inputStream = new DataInputStream(connection.getInputStream ());
StringBuffer buffer = new StringBuffer;
String line;
while ((str = input.readLine()) != null) {
buffer.append(line);
}
inputStream.close ();