我想从 https://url 下载一个 apk 文件。当我第一次尝试下载时,它说
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
所以我搜索了互联网并添加了 network_secuirty_config.xml 文件。
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<domain includeSubdomains="true">companyName.in</domain>
<trust-anchors>
<certificates src="@raw/rapid"/>
</trust-anchors>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">phantom.companyName.in</domain>
</domain-config>
</domain-config>
</network-security-config>
现在的错误是
Stop requested with status HTTP_DATA_ERROR: Hostname phantom.companyName.in not verified:
我已经搜索了所有地方,但找不到解决错误的方法。这是我的下载管理器请求入队代码。
//create download request
DownloadManager.Request request = new DownloadManager.Request(uri);
//allow types of network to download files
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setMimeType(FileUtils.getMimeType(uri.toString()));
request.setTitle("Download");
request.setDescription("Downloading File...");
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, "/" + filename);
//get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
m_downloadID = manager.enqueue(request);
PS:-我在应用程序中为普通的 https 请求添加了主机名验证器,这就是我发送 https 请求的方式。