zoukankan      html  css  js  c++  java
  • 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();
                }
            }
  • 相关阅读:
    搭建Nginx反向代理做内网域名转发
    网站监测脚本
    Nginx启动脚本
    L2TP用户添加和删除、搜索脚本
    CentOS Linux 安装IPSec+L2TP
    Nginx认证
    Nginx配置HTTPS
    Nginx 如何处理一个请求
    HTTP协议原理
    DNS解析流程
  • 原文地址:https://www.cnblogs.com/padazala/p/13686508.html
Copyright © 2011-2022 走看看