• spring之httpclient doget请求


    /**
         * @param url        请求地址
         * @param jsonString 加密后的字符串
         * @return
         * @throws ClientProtocolException
         * @throws IOException             返回请求后的报文  JSON字符串
         */
        public static String doGet(String url, String jsonString) throws IOException {

            // 创建Httpclient对象
            CloseableHttpClient httpClient = HttpClients.createDefault();
            CloseableHttpResponse response = null;
            String resultString = "";
            // 创建参数列表
            if (jsonString != null & !"".equals(jsonString)) {
                StringEntity strEnt = new StringEntity(jsonString.toString(), "UTF-8");//解决中文乱码问题
                strEnt.setContentEncoding("UTF-8");
                strEnt.setContentType("application/json");
            }
            // 创建Http get请求
            HttpGet httpGet = new HttpGet(url+"?"+jsonString);
            // 执行http请求
            response = httpClient.execute(httpGet);
            resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
            return resultString;
        }

  • 相关阅读:
    .NetCore教程之 EFCore连接Mysql DBFirst模式
    .Net EF6+Mysql 环境搭建
    SQL实用
    前端文章分享
    mac怎样运行vue项目
    Cadence 操作技巧总结3:拼板技巧总结
    TCL语言控制Modelsim仿真 2
    TCL语言控制Modelsim仿真 1
    Cadence 操作技巧总结2:模块化布局
    Cadence 操作技巧总结1:测试点的生成1
  • 原文地址:https://www.cnblogs.com/wirr/p/8397729.html
Copyright © 2020-2023  润新知