String query = "name=" + URLEncoder.encode("Elliotte Rusty Harold");
query += "&";
query += "email=" + URLEncoder.encode("elharo@sunsite.unc.edu");
int cl = query.length();
try {
// open the connection and prepare it to POST
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setAllowUserInteraction(false);
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
// The POST line, the Accept line, and
// the content-type headers are sent by the URLConnection.
// We just need to send the data
dos.writeBytes(query);
dos.close();
// Read the response
DataInputStream dis = new DataInputStream(uc.getInputStream());
String nextline;
while((nextline = dis.readLine()) != null) {
System.out.println(nextline);
}
dis.close();
}
catch (Exception e) {
System.err.println(e);
}