• HttpClient 通过 httpPost发送数据模板


         String url = "";
            CloseableHttpClient httpClient = HttpClientBuilder.create().build();
            HttpPost httpPost = new HttpPost(url);
            StringEntity stringEntity = new StringEntity(JSON.toJSONString(data), "UTF-8");
            httpPost.setEntity(stringEntity);
            httpPost.setHeader("Content-Type", "application/json;charset=utf8");
            CloseableHttpResponse response = null;
            try {
                // 由客户端执行(发送)Post请求
                response = httpClient.execute(httpPost);
                // 从响应模型中获取响应实体
                HttpEntity responseEntity = response.getEntity();
                if (responseEntity != null) {
                    log.info("响应内容:" + EntityUtils.toString(responseEntity));
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    // 释放资源
                    if (httpClient != null) {
                        httpClient.close();
                    }
                    if (response != null) {
                        response.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
  • 相关阅读:
    word编号变黑块
    恢复未保存的word
    协方差分析
    SAS字体变大
    可变区组长度--区组随机
    adv and disadv of oncology clinical trial endpoints
    非劣效试验界值确定
    Computer Science
    Compuer Science
    随笔
  • 原文地址:https://www.cnblogs.com/padazala/p/13686508.html
Copyright © 2020-2023  润新知