Accept-Encoding“, “gzip, deflate“解压缩造成的乱码问题

这里写自定义目录标题

java 代码模拟postman请求 response乱码

post.setHeader(“Accept-Encoding”, “gzip, deflate”);
浏览器和postman 会自动解压缩,不会乱码,java代码没有设置解压缩,所以乱码,注释掉就可以了
或者在 获取response entity的时候,解压

HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
    // 按指定编码转换结果实体为String类型
    body = EntityUtils.toString(new GzipDecompressingEntity(entity), "UTF-8");
}
posted @ 2022-03-14 19:06  明晓默  阅读(696)  评论(0编辑  收藏  举报