EntityUtils.toString(entity,"UTF-8");无返回中文都乱码

查尔斯风 2017-09-30 04:56:13
HttpPost httppost = new HttpPost(location);
HttpEntity re = new StringEntity(reqData, HTTP.UTF_8);
setHeaders(httppost, headerType);//设置header utf-8方法
httppost.setEntity(re);
HttpResponse response = httpClient.execute(httppost);
result = EntityUtils.toString(response.getEntity(),"UTF-8");

------------------------------
result 乱码(无论是否有中文)。各种格式尝试过了,gbk也不行。
网上找到3种转格式方法试过了,也没用(
1、EntityUtils.toString(response.getEntity(),"GBK");
2、new String(EntityUtils.toString(response.getEntity()).getBytes("ISO-8859-1"),"GBK");
3、new String(result.getBytes("ISO-8859-1"),"GBK");)。
大神们,看看还有什么办法,搞定这个乱码问题
...全文
1996 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
查尔斯风 2017-10-09
  • 打赏
  • 举报
回复
大神哪去了

51,412

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧