我有一個問題,即當我嘗試打開這個網址我HttpsURLConnection的將拋出EOFException類:http://www.weather.com.cn/data/cityinfo/101210101.html的Android HttpsURLConnection的java.io.EOFException的
代碼:
URL url = new URL("http://www.weather.com.cn/data/cityinfo/101210101.html");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
InputStream in = new BufferedInputStream(connection.getInputStream());
StringBuffer out = new StringBuffer();
byte[] b = new byte[1024];
for(int n;(n = in.read(b)) != -1;){
out.append(new String(b, 0, n));
}
以下是堆棧跟蹤:
java.io.EOFException
at com.android.okio.RealBufferedSource.require(RealBufferedSource.java:64)
at com.android.okio.RealBufferedSource.readIntLe(RealBufferedSource.java:115)
at com.android.okio.GzipSource.consumeTrailer(GzipSource.java:168)
at com.android.okio.GzipSource.read(GzipSource.java:87)
at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)
at java.io.InputStream.read(InputStream.java:162)
at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:149)
at java.io.BufferedInputStream.read(BufferedInputStream.java:295)
at java.io.InputStream.read(InputStream.java:162)
at com.coolweather.app.coolweather.util.HttpUtil$1.run(HttpUtil.java:47)
at java.lang.Thread.run(Thread.java:818)
你只能在Android得到這個問題,因爲它工作正常的java程序? –
當我在同一個域上打開這樣的URL時,我沒有得到這個問題: http://www.weather.com.cn/data/list3/city.xml http://www.weather.com .cn/data/list3/city19.xml –