您的位置:首页 > 理论基础 > 计算机网络

Http请求post方法,请求和响应中文乱码问题的一点解决方法

2016-12-19 20:39 1971 查看
请求的解决方法:

        把封装好的json数据,通过new一个ByteArrayEntity的方式,在post的entity里设置UTF-8格式的byte类型的json数据,保证中文的正确传输。

String json = JacksonUtil.toJson(postMap);
HttpEntity entity = new ByteArrayEntity(json.getBytes("UTF-8"));
post.setEntity(entity);
HttpResponse response = client.execute(post);


响应的解决方法:

 

       

            HttpEntity entity = resp.getEntity();
String respContent = EntityUtils.toString(entity , "GBK").trim();


          EntityUtils的toString方法,附带GBK的编码格式即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HTTP post请求 乱码