• 传入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 ;
    }
  • 相关阅读:
    网络爬虫基础练习
    综合练习:词频统计
    画图
    Hadoop综合大作业
    hive基本操作与应用
    理解MapReduce计算构架
    熟悉HBase基本操作
    爬虫大作业
    熟悉常用的HDFS操作
    数据结构化与保存
  • 原文地址:https://www.cnblogs.com/syscn/p/8617295.html
Copyright © 2020-2023  润新知