• java发送post请求 ,请求数据放到body里


    java利用httpclient发送post请求 ,请求数据放到body里。

    /**
         * post请求 ,请求数据放到body里
         *
         * @author lifq
         *
         *         2017年3月15日 下午3:47:04
         */
        public static String doPostBodyData(String url, String bodyData) throws Exception {
            String result = "";
            CloseableHttpClient httpClient = null;
            CloseableHttpResponse response = null;
            try {
                HttpPost httpPost = getHttpPost(url, null); // 请求地址
                httpPost.setEntity(new StringEntity(bodyData, Encoding));
                httpClient = getHttpClient();
                // 得到返回的response.
                response = httpClient.execute(httpPost);
                HttpEntity entity = response.getEntity();
                result = getResult(entity, Encoding);
            } catch (Exception e) {
                throw e;
            } finally {
                // 关闭httpClient
                if (null != httpClient) {
                    httpClient.close();
                }
                // 关闭response
                if (null != response) {
                    EntityUtils.consume(response.getEntity()); // 会自动释放连接
                    response.close();
                }
            }
            return result;
        }

    限时领取免费Java相关资料,涵盖了Java、Redis、MongoDB、MySQL、Zookeeper、Spring Cloud、Dubbo/Kafka、Hadoop、Hbase、Flink等高并发分布式、大数据、机器学习等技术。

    资料传送门:https://mp.weixin.qq.com/s/u2b_NVNuMuAPE0w4lc45fw

     

    关注下方公众号即可免费领取:

    Java碎碎念公众号

  • 相关阅读:
    打印水仙花数
    打印从1到k之间的所有素数
    Fibonacci数列小程序
    Fibonacci数
    水仙花数
    猴子吃桃问题
    5个数求最值—南阳acm
    三个数从小到大排序—南阳acm
    南阳acm奇偶数分离
    find the safest road--hdu1596
  • 原文地址:https://www.cnblogs.com/haha12/p/6693754.html
Copyright © 2020-2023  润新知