zoukankan      html  css  js  c++  java
  • 传入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请求
    好文要顶 关注我 收藏该文  

     

     
  • 相关阅读:
    泰勒综合
    滤波器、窗等的系数为什么是对称的?
    l'alphabet en francais
    弄清for循环的本质
    js中的闭包
    js中用正则表达式
    java Calendar
    Android实现XML解析技术
    junit4 详解
    redhat vi 命令
  • 原文地址:https://www.cnblogs.com/muhy/p/10402119.html
Copyright © 2011-2022 走看看