String params = "userId=XXX&name=NNNNN";
String responseString = "";
try{
//打开连接
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
System.out.println("params"+params);
out.write(params);
out.flush();
out.close();
String strLine = "";
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
while ((strLine = reader.readLine()) != null) {
responseString += strLine + "\n";
}
in.close();
System.err.print("请求的返回信息:"+responseString);
}catch(Exception e){
e.printStackTrace();
}