为什么https下载被PAUSED_WAITING_TO_RETRY暂停? [英] Why are https downloads pausing with PAUSED_WAITING_TO_RETRY?

查看:328
本文介绍了为什么https下载被PAUSED_WAITING_TO_RETRY暂停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android中的 DownloadManager 服务通过https URL下载文件,例如 https://www.antennahouse.com/XSLsample /pdf/sample-link_1.pdf .这些文件没有(当前)受密码保护,以防万一.

I'm using the DownloadManager service in Android to download files over https URLs, such as https://www.antennahouse.com/XSLsample/pdf/sample-link_1.pdf. The files are not (currently) password protected, in case that makes any difference.

一旦我排队了一个下载请求,DownloadManager便开始下载,但似乎挂起了.当我检查状态时,我得到

Once I enqueue a download request, the DownloadManager starts the download, but it seems to hang. When I check the status, I get

COLUMN_BYTES_DOWNLOADED_SO_FAR: 0
COLUMN_STATUS: 4
COLUMN_REASON: 1

COLUMN_STATUS 4是 STATUS_PAUSED ,当下载等待重试或恢复."​​

COLUMN_STATUS 4 is STATUS_PAUSED, "when the download is waiting to retry or resume."

COLUMN_REASON 1是 PAUSED_WAITING_TO_RETRY ,已暂停,因为发生了网络错误,并且下载管理器正在等待重试请求."但是似乎没有办法确定发生了什么网络错误.下载永远不会成功完成.

COLUMN_REASON 1 is PAUSED_WAITING_TO_RETRY, "when the download is paused because some network error occurred and the download manager is waiting before retrying the request." But there doesn't seem to be a way to determine what network error occurred. The download never successfully completes.

我已经检查了logcat监视器是否有相关的警告和错误,但是什么也没发现.

I've checked the logcat monitor for related warnings and errors, but found nothing.

我已经在内部和公共的多个不同服务器上尝试了此方法,结果都是相同的.

I've tried this with multiple different servers, both in-house and public, with the same result.

没有明显的网络问题:Wi-Fi连接已建立,并且使用http://进行下载正常:文件被立即下载并出现在文件系统中的指定目的地

There is no obvious network problem: the Wi-Fi connection is up, and downloads using http:// work just fine: the file is downloaded promptly and appears in the filesystem at the specified destination.

在使用https下载的情况下,我们的服务器日志显示,从服务器的角度来看,文件已成功提供.在便携式计算机上的浏览器中测试相同的https URL,可以成功下载文件,而在开发人员工具网络面板中不会出现任何明显的问题或额外的协商.

In the case of https downloads, our server logs show that the files are being successfully served from the server's point of view. Testing the same https URLs in a browser on a laptop result in successful download of the files, without any obvious problems or extra negotiations showing up in the developer tools network panel.

我的代码(摘要):

sManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request req = new DownloadManager.Request(sourceURI);
final Uri destinationUri = Uri.fromFile(destinationFile);
req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI
            | DownloadManager.Request.NETWORK_MOBILE)
        .setDestinationUri(destinationUri)
        .setMimeType(...);

long id = sManager.enqueue(req);

摘要:通过DownloadManager启动的https下载会无限期挂起,而相同的https下载在浏览器中可以正常运行,而普通的http下载对于使用DownloadManager的同一应用程序也可以正常运行.我最好的线索是PAUSED_WAITING_TO_RETRY指示发生了某些网络错误".如何确定网络错误是什么?

Summary: An https download started via DownloadManager hangs indefinitely, while the same https download works fine in a browser, and plain http downloads work fine with the same app using DownloadManager. The best clue I have is that PAUSED_WAITING_TO_RETRY indicates "some network error occurred." How can I determine what the network error is?

推荐答案

最接近的原因似乎是CertificateException:CertPathValidatorException:Trust anchor for certification path not found.我通过

The proximate cause seems to be a CertificateException: CertPathValidatorException: Trust anchor for certification path not found. I found this out by using an HttpURLConnection directly (thanks to @CommonsWare for the suggestion) instead of the DownloadManager, which gave more direct access to exceptions. (This was true in the case of our in-house server. It does not seem to be the case with the sample URL I mentioned, which seemed to be having the same problem with DownloadManager ... but maybe that same problem had a different cause.)

根CA(在所有情况下)是"AddTrust外部CA根",它出现在设备上设置">安全性">受信任的凭据"下的受信任CA列表中.因此,如果这是受信任的CA根,为什么会有找不到证书路径的信任锚"异常?

The root CA (in all cases) is "AddTrust External CA Root", which is present in the list of trusted CAs on the device, under Settings > Security > Trusted credentials. So if this is a trusted CA root, why is there a "Trust anchor for certification path not found" exception?

服务器中的服务链中似乎没有包含中间CA,如此处进行了描述.实际上,使用openssl s_client -connect检查CA链可以确认不包括中间CA. Android文档文章提出了两种可能的解决方案:包括中间层CA位于服务器链中,或者通过创建特殊的TrustManager在应用程序中显式信任它们.我希望做前者.

It looks like there is an intermediate CA not being included in the chain served by the server, as described here. In fact, using openssl s_client -connect to check the CA chain confirms that the intermediate CA's are not included. The Android doc article suggests two possible solutions: include the intermediate CA's in the server chain, or explicitly trust them in the app by creating a special TrustManager. I hope to do the former.

这篇关于为什么https下载被PAUSED_WAITING_TO_RETRY暂停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆