傳入json字符串的post請求


/**
* 傳入json字符串的post請求
* @Title: getRequsetData 
* @Description: TODO
* @param @param url
* @param @param json {"refund_fee":"1","total_fee":"1","out_trade_no":"20180319184601983860"}
* @param @return
* @param @throws Exception 設定文件 
* @return JSONObject 返回類型 
* @throws
*/
public static JSONObject getRequsetData(String url,String json) throws Exception{
System.out.println("-----------傳入json:---------------------------"+json);
HttpPost httpPost = new HttpPost(url);
HttpClient httpClient = HttpClients.createDefault();
StringEntity postEntity = new StringEntity(json, "UTF-8");
httpPost.addHeader("Content-Type", "application/json");
httpPost.setEntity(postEntity);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String b = EntityUtils.toString(httpEntity, "UTF-8");
System.out.println("-----------返回值:---------------------------"+b);
JSONObject JS = JSONObject.fromObject(b);
return JS ;
}
復制代碼

 

 
 
標簽:  post請求
好文要頂  關注我  收藏該文   

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM