lingochamp / FileDownloader

Multitask、MultiThread(MultiConnection)、Breakpoint-resume、High-concurrency、Simple to use、Single/NotSingle-process
Apache License 2.0
11.04k stars 2.2k forks source link

下载失败,OnError中回调Unexpected status line: #1255

Closed zhiyong926 closed 5 years ago

zhiyong926 commented 5 years ago

TasksManagerDemoActivity.java中的 protected void error(BaseDownloadTask task, Throwable e) { super.error(task, e);

} 中回调出现e.getMessage = Unexpected status line: 用户网络连接正常,目前是在OPPO/Vivo手机中出现 【手机型号】vivo X9s Plus【系统版本】8.1.0 【手机厂商】OPPO【手机型号】OPPO A59s【系统版本】5.1

rantianhua commented 5 years ago

请提供下详细的 error 信息,比如错误堆栈,如果能提供完整的日志就更好了。Unexpected status line 这个不是 FileDownloader 抛出的错误信息,所以不能根据这个断定问题。

zhiyong926 commented 5 years ago

目前就是无法利用手头设备复现,都是用户设备回传的错误提示信息,难道就只有我1个人遇到这个问题吗?

zhiyong926 commented 5 years ago

网上有人说用DefaultHttpClient和HttpPost可以解决?烦请大神帮忙分析一下 http://www.apkbus.com/thread-318640-1-1.html

rantianhua commented 5 years ago

这其实是 OkHttp 的问题,建议参考 https://github.com/square/retrofit/issues/805 。HTTP/1.1 默认是连接是 Keep-Alive ,目的是复用连接,你可以参照这个连接里面改成短连接试试。

zhiyong926 commented 5 years ago

大神,请问是在Demo里的TasksManagerDemoActivity.java中: private View.OnClickListener taskActionOnClickListener = new View.OnClickListener() { @Override public void onClick(View v) { if (v.getTag() == null) { return; }

            TaskItemViewHolder holder = (TaskItemViewHolder) v.getTag();

            CharSequence action = ((TextView) v).getText();
            if (action.equals(v.getResources().getString(R.string.pause))) {
                // to pause
                FileDownloader.getImpl().pause(holder.id);
            } else if (action.equals(v.getResources().getString(R.string.start))) {
                // to start
                // to start
                final TasksManagerModel model = TasksManager.getImpl().get(holder.position);
                final BaseDownloadTask task = FileDownloader.getImpl().create(model.getUrl())
                        .setPath(model.getPath())
                        .setCallbackProgressTimes(100)
                        **.addHeader("Connection", "close")**
                        .setListener(taskDownloadListener);

此处添加.addHeader("Connection", "close")吗?若不是,还请在您写的Demo中具体哪里添加帮忙说明一下,我是小白,麻烦大神了 @rantianhua

rantianhua commented 5 years ago

是的。