post方法,可以带headerpublic static String doPostWithHeader(String url, JSONObject header, Object param) throws IOException{
URL visitUrl = new URL(url);
HttpURLConnection urlConnection = (HttpURLConnection)visitUrl.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
for(String propertyName : header.keySet()){
String propertyValue = header.getString(propertyName);
urlConnection.setRequestProperty(propertyName, propertyValue);
}
PrintWriter out = new PrintWriter(urlConnection.getOutputStream());
out.print(param);
out.flush();
InputStream is = urlConnection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
return readAll(rd);
}