diff --git a/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java b/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java index 05d6e1a2b..31eebc720 100644 --- a/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java +++ b/webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java @@ -7,6 +7,7 @@ import java.util.Optional; import org.apache.commons.io.IOUtils; +import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.impl.client.CloseableHttpClient; @@ -111,7 +112,8 @@ public void setThread(int thread) { } protected Page handleResponse(Request request, String charset, HttpResponse httpResponse, Task task) throws IOException { - byte[] bytes = IOUtils.toByteArray(httpResponse.getEntity().getContent()); + HttpEntity entity = httpResponse.getEntity(); + byte[] bytes = entity != null ? IOUtils.toByteArray(entity.getContent()) : new byte[0];; String contentType = httpResponse.getEntity().getContentType() == null ? "" : httpResponse.getEntity().getContentType().getValue(); Page page = new Page(); page.setBytes(bytes);