1url = new URL("http://...");
2connection = (HttpURLConnection) url.openConnection();
3connection.setDoOutput(true);
4connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
5connection.setRequestMethod("POST");
6
7request = new OutputStreamWriter(connection.getOutputStream());
8request.write(params);
9request.flush();
10request.close();
11String line;
12
13int status = connection.getResponseCode();
14if(status < 400) {
15
16 InputStreamReader isr = new InputStreamReader(connection.getInputStream());
17 ...
18} else{
19 InputStreamReader isr = new InputStreamReader(connection.getErrorStream());
20 ...
21}
22