url = new URL("http://...");
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestMethod("POST");
request = new OutputStreamWriter(connection.getOutputStream());
request.write(params);
request.flush();
request.close();
String line;
int status = connection.getResponseCode();
if(status < 400) {
InputStreamReader isr = new InputStreamReader(connection.getInputStream());
...
} else{
InputStreamReader isr = new InputStreamReader(connection.getErrorStream());
...
}