1

我正在尝试下载 php 页面的内容(只有 3 个字),但我得到java.io.IOException: unexpected end of stream. 这是下载代码:

// 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)

我尝试调试,最后一个值result是这样的: 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>

欢迎任何想法!

4

1 回答 1

2

似乎 Content-Length 设置不正确(来源显示 FixedLengthOutputStream.close 在大小不匹配时抛出 IOException )

此外,在您的编辑中,您显示您的页面正在返回一个 '404,这表明您没有使用正确的ziplist.php. 仔细检查您使用的 URL :)

于 2013-08-18T11:10:33.430 回答