码迷,mamicode.com
首页 > Web开发 > 详细

httpclient 直接json请求

时间:2017-02-15 00:47:40      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:etc   http   entity   style   中文乱码   policy   check   sea   util   

已有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请求

标签:etc   http   entity   style   中文乱码   policy   check   sea   util   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!