80,360
社区成员
发帖
与我相关
我的任务
分享
public class HttpAssist {
public static String doPost(JSONObject json) throws IOException{
URL postUrl = new URL(Config.url);
HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.connect();
OutputStreamWriter out = new OutputStreamWriter (connection
.getOutputStream());
out.write( Config.getParameterName + "=" + json.toString());
out.flush();
out.close(); // flush and close
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
String line="";
String res = "";
while ((line = reader.readLine()) != null){
res += line;
System.out.println(line);
}
reader.close();
connection.disconnect();
return res;
}
}