user2767013
user2767013

Reputation: 43

Why am I getting EOFException when connecting to a specific website using Jsoup?

I'm trying to get some data from this website http://www.mof.gov.cn/, and I keep on getting EOFException:

The connect command is very basic: Jsoup.connect("http://www.mof.gov.cn/").ignoreContentType(true).userAgent("Mozilla/5.0(Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0").timeout(30000).get();

The EOFException is that:

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.BufferedInputStream.read1(BufferedInputStream.java:256)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at org.jsoup.helper.DataUtil.readToByteBuffer(DataUtil.java:124)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:464)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
at com.staging.Crawfinance.main(Crawfinance.java:30)

Any idea why? Many thanks.

Upvotes: 2

Views: 2096

Answers (1)

Georgi Eftimov
Georgi Eftimov

Reputation: 124

Please try this with a valid charset name :

Document doc = Jsoup.parse(new URL("http://www.mof.gov.cn/").openStream(), "UTF-8", "http://www.mof.gov.cn/");

Upvotes: 3

Related Questions