java.io.EOFException

使用webclient抓取网页时报错:

java.io.EOFException
	at java.util.zip.GZIPInputStream.readUByte(GZIPInputStream.java:207)
	at java.util.zip.GZIPInputStream.readUShort(GZIPInputStream.java:197)
	at java.util.zip.GZIPInputStream.readUInt(GZIPInputStream.java:189)
	at java.util.zip.GZIPInputStream.readTrailer(GZIPInputStream.java:179)
	at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:94)
	at java.io.FilterInputStream.read(FilterInputStream.java:90)
	at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:68)
	at com.gargoylesoftware.htmlunit.HttpWebConnection.downloadContent(HttpWebConnection.java:693)
	at com.gargoylesoftware.htmlunit.HttpWebConnection.downloadResponseBody(HttpWebConnection.java:675)
	at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:201)
	at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1324)
	at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1382)
	at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1242)
	at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:348)
	at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:434)
	at com.pa.crawler.util.WebClientUtil.getWebRequestPage(WebClientUtil.java:571)

貌似使用httpclient不会。

添加头信息

client.addRequestHeader("Accept-Encoding", "");

后不会抛出该异常。

你可能感兴趣的:(爬虫,webclient)