/**
* 传入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 ;
}
传入json字符串的post请求

 

 
 
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 ;
}
传入json字符串的post请求

 

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2021-04-14
  • 2022-12-23
  • 2022-01-22
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-14
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
相关资源
相似解决方案