2

如何在android中使用https协议下载文件?我正在尝试使用它,但不断收到错误消息。

我的下载代码:

var fileTransfer = new FileTransfer();
          fileTransfer.download(
                task_url,
                fileListDir + fileName,
            function(entry) {
                mylog("download complete: " + entry.fullPath);
            },
            function(error) {
                mylog("download error source " + error.source);
                mylog("download error target " + error.target);
                mylog("upload error code" + error.code);
            });

我的日志

11-19 13:56:13.339: E/FileTransfer(17969): {"target":"/mnt/sdcard/task1/Picture_4.jpg","source":"https://91.228.199.95/ksiywFac63f2hs/fotos .gleb/Picture_4.jpg","code":3} 11-19 13:56:13.339: E/FileTransfer(17969): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: 用于认证的信任锚找不到路径。11-19 13:56:13.339: E/FileTransfer(17969): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:477) 11-19 13:56:13.339: E/ FileTransfer(17969):在 org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:328) 11-19 13:56:13.339:E/FileTransfer(17969):在 org.apache.harmony .luni.internal.net.www.protocol.http.HttpConnection。下载(FileTransfer.java:486) 11-19 13:56:13.339: E/FileTransfer(17969): at org.apache.cordova.FileTransfer.execute(FileTransfer.java:88) 11-19 13:56:13.339: E/FileTransfer(17969):在 org.apache.cordova.api.PluginManager$1.run(PluginManager.java:231) 11-19 13:56:13.339:E/FileTransfer(17969):在 java.lang.Thread。运行(Thread.java:1019)11-19 13:56:13.339:E/FileTransfer(17969):原因:java.security.cert.CertificateException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚. 11-19 13:56:13.339: E/FileTransfer(17969): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:161) 11-19 13:56:13.339: E/文件传输(17969):在 org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl。java:664) 11-19 13:56:13.339: E/FileTransfer(17969): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(本机方法) 11-19 13:56:13.339: E /FileTransfer(17969): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:474) 11-19 13:56:13.339: E/FileTransfer(17969): ... 还有 10 个11-19 13:56:13.339:E/FileTransfer(17969):原因:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。11-19 13:56:13.339: E/FileTransfer(17969): 在 org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:207) 11-19 13:56:13.339: E/FileTransfer(17969) : 在 java.security.cert.CertPathValidator.validate(CertPathValidator.java:197) 11-19 13:56:13.339: E/FileTransfer(17969): at org.

4

1 回答 1

4

答案是将旧的 cordova 更改为 cordova 2.2.0 并在代码中写入 true,一些 this

var fileTransfer = new FileTransfer();
      fileTransfer.download(
            task_url,
            fileListDir + fileName,
        function(entry) {
            mylog("download complete: " + entry.fullPath);
        },
        function(error) {
            mylog("download error source " + error.source);
            mylog("download error target " + error.target);
            mylog("upload error code" + error.code);
        }, true);

这是工作!!!谢谢西蒙麦克唐纳德!

于 2012-11-19T14:18:59.140 回答