首页 > Web开发 > 详细

httpclient 直接json请求

时间:2017-02-15 00:45:09      阅读:194      评论:0      收藏:0      [点我收藏+]

已有json请求参数

        String url = "http://192.168.15.23:8180/ab_admin?action=policy_check";
         
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(url);

        StringEntity entity = new StringEntity(param, "utf-8");//解决中文乱码问题    
        entity.setContentEncoding("UTF-8");
        entity.setContentType("application/json");
        httpPost.setEntity(entity);
        CloseableHttpResponse response = httpclient.execute(httpPost);
        String respContent = "";
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity he = response.getEntity();
            respContent = EntityUtils.toString(he, "UTF-8");
            return respContent;
        }

 

httpclient 直接json请求

原文:http://www.cnblogs.com/applemoon/p/6399683.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!