📅  最后修改于: 2022-03-11 14:52:03.544000             🧑  作者: Mango
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());
...
}