Apache html 响应 returns 乱码
Apache html response returns gibberish
我正在尝试从远程网站获得 HTML 响应,但我得到了这样的结果:
ס×?×? ×?×? ×?×? ×?×?
而不是希伯来字母或符号。
这是我的代码:
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.build();
HttpGet httpget = new HttpGet(URL);
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String s=null;
if (entity != null) {
s= EntityUtils.toString(entity);
}
有人知道问题出在哪里吗?
根据文档,
The content is converted using the character set from the entity (if any), failing that, "ISO-8859-1" is used.
正在使用默认字符集,因为您没有提供默认字符集,它不能正确映射这些字符 - 您可能应该改用 UTF-8。试试这个。
s= EntityUtils.toString(entity, "UTF-8");
我正在尝试从远程网站获得 HTML 响应,但我得到了这样的结果:
ס×?×? ×?×? ×?×? ×?×?
而不是希伯来字母或符号。
这是我的代码:
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.build();
HttpGet httpget = new HttpGet(URL);
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String s=null;
if (entity != null) {
s= EntityUtils.toString(entity);
}
有人知道问题出在哪里吗?
根据文档,
The content is converted using the character set from the entity (if any), failing that, "ISO-8859-1" is used.
正在使用默认字符集,因为您没有提供默认字符集,它不能正确映射这些字符 - 您可能应该改用 UTF-8。试试这个。
s= EntityUtils.toString(entity, "UTF-8");