public static String XXXPost(String url, String json)throws Exception{
//創建一個DefaultHttpClient的實例
HttpClient httpClient = new DefaultHttpClient();
//創建一個HttpPost對象,傳入目標的網絡地址:
HttpPost post = new HttpPost(url);
//參數傳遞
StringEntity postingString = new StringEntity(json);// json傳遞
postingString.setContentType("application/x-www-form-urlencoded");
//參數傳入
post.setEntity(postingString);
//執行execute()方法之后會返回一個HttpResponse對象,服務器所返回的所有信息就保護在HttpResponse里面.
先取出服務器返回的狀態碼,如果等於200就說明請求和響應都成功了:
HttpResponse response = httpClient.execute(post);
HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity);
return content;
}
下面是一位大神的詳細用法:
https://www.cnblogs.com/xiayahui/p/5623947.html