访问“https://www.beijing-hyundai.om.cn”网站,解析网页时报出java.io.EOFException #409

Open
damaouxiang123 opened this Issue Dec 5, 2016 · 2 comments

Projects

None yet

3 participants

@damaouxiang123
damaouxiang123 commented Dec 5, 2016 edited

如下代码:
protected String getContent(String charset, HttpResponse httpResponse) throws IOException {
if (charset == null) {
byte[] contentBytes = IOUtils.toByteArray(httpResponse.getEntity().getContent());
String htmlCharset = getHtmlCharset(httpResponse, contentBytes);
if (htmlCharset != null) {
return new String(contentBytes, htmlCharset);
} else {
logger.warn("Charset autodetect failed, use {} as charset. Please specify charset in Site.setCharset()", Charset.defaultCharset());
return new String(contentBytes);
}
} else {
return IOUtils.toString(httpResponse.getEntity().getContent(), charset);
}
}
在IOUtils.toByteArray执行时,报出java.io.EOFException,求解决方案。多谢

@code4craft
Owner

是每次都这样吗?看起来可能是网络比较慢没抓全。

@ningpp
ningpp commented Jan 5, 2017 edited

CloseableHttpClient httpClient = HttpClients.custom() .disableContentCompression() .build();
禁用压缩就不报错了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment