IOException-读取HTML文件时流意外结束 [英] IOException - Unexpected end of stream while reading html file
问题描述
我正在尝试下载php页面的内容(仅3个字),但是却出现了 java.io.IOException:流的意外结尾
。这是下载代码:
I am trying to download the content of a php page (it is just 3 words), but I am getting java.io.IOException: unexpected end of stream
. This is the code for downloading:
// Download file list
String zipListUrl = baseUrl + ziplist;
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(zipListUrl);
try {
HttpResponse response = client.execute(request);
// txtResult.setText(HttpHelper.request(response));
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
String line = null;
String result = null;
while ((line = reader.readLine()) != null) {
// fileNames.add(line);
result += line;
}
in.close();
// Turn arraylist into simple array
// finalFileNames = (String[]) fileNames.toArray();
Log.i(LOG_TAG, /* Arrays.toString(finalFileNames) */result);
} catch (Exception ex) {
ex.printStackTrace();
Log.d(LOG_TAG, "Exception ex1 = " + ex.toString());
}
这是一个例外:
08-18 11:11:04.312: W/HttpTransport(3101): unexpected end of stream
08-18 11:11:04.312: W/HttpTransport(3101): java.io.IOException: unexpected end of stream
08-18 11:11:04.312: W/HttpTransport(3101): at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
08-18 11:11:04.312: W/HttpTransport(3101): at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:83)
08-18 11:11:04.312: W/HttpTransport(3101): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:895)
08-18 11:11:04.312: W/HttpTransport(3101): at net.zedge.android.api.request.BaseApiRequest.run(BaseApiRequest.java:50)
08-18 11:11:04.312: W/HttpTransport(3101): at net.zedge.android.api.request.BaseApiRequest$1.run(BaseApiRequest.java:84)
08-18 11:11:04.312: W/HttpTransport(3101): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
08-18 11:11:04.312: W/HttpTransport(3101): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-18 11:11:04.312: W/HttpTransport(3101): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-18 11:11:04.312: W/HttpTransport(3101): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-18 11:11:04.312: W/HttpTransport(3101): at java.lang.Thread.run(Thread.java:841)
08-18 11:11:04.342: W/HttpTransport(3101): unexpected end of stream
08-18 11:11:04.342: W/HttpTransport(3101): java.io.IOException: unexpected end of stream
08-18 11:11:04.342: W/HttpTransport(3101): at libcore.net.http.FixedLengthOutputStream.close(FixedLengthOutputStream.java:58)
08-18 11:11:04.342: W/HttpTransport(3101): at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:83)
08-18 11:11:04.342: W/HttpTransport(3101): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:895)
08-18 11:11:04.342: W/HttpTransport(3101): at net.zedge.android.api.request.BaseApiRequest.run(BaseApiRequest.java:50)
08-18 11:11:04.342: W/HttpTransport(3101): at net.zedge.android.api.request.BaseApiRequest$1.run(BaseApiRequest.java:84)
08-18 11:11:04.342: W/HttpTransport(3101): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
08-18 11:11:04.342: W/HttpTransport(3101): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-18 11:11:04.342: W/HttpTransport(3101): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-18 11:11:04.342: W/HttpTransport(3101): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-18 11:11:04.342: W/HttpTransport(3101): at java.lang.Thread.run(Thread.java:841)
我尝试调试,结果
的最后一个值是:
null<!DOCTYPE HTML PUBLIC-// IETF // DTD HTML 2.0 // EN>< html>< head>标题404未找到< / title< / head< body> < h1>未找到< / h1>< p>在此服务器上未找到请求的URL/ziplist.php。</p><p>此外,尝试使用以下命令时遇到404 Not Founderror。 < / p>< / body>< / html>
I tried debugging, and the last value of result
is this:
null<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /ziplist.php was not found on this server.</p><p>Additionally, a 404 Not Founderror was encountered while trying to use an ErrorDocument to handle the request.</p></body></html>
欢迎任何想法!
推荐答案
似乎Content-Length设置不正确(源显示FixedLengthOutputStream.close在大小不匹配时引发IOException )
It would seem that Content-Length is set incorrectly (the source shows that FixedLengthOutputStream.close throws IOException on a size mismatch)
此外,在您的编辑中,您还显示页面返回'404,表示您未使用<$ c $的正确URL。 c> ziplis t.php 。仔细检查您正在使用的网址:)
Also, in your edit you're showing that your page is returning a '404, which indicates that you're not using the correct URL for ziplist.php
. Double check the URL you're using :)
这篇关于IOException-读取HTML文件时流意外结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!