如何从android phonegap应用程序中的https URI下载文件?

时间:2012-11-19 11:46:34

标签: javascript android html5 cordova

如何在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):   { “目标”: “/mnt/sdcard/task1/Picture_4.jpg”, “源”: “https://91.228.199.95/ksiywFac63f2hs/fotos.gleb/Picture_4.jpg”, “代码”: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):at   org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:328)   11-19 13:56:13.339:E / FileTransfer(17969):at   org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.setupSecureSocket(HttpConnection.java:185)   11-19 13:56:13.339:E / FileTransfer(17969):at   org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl $ HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:433)   11-19 13:56:13.339:E / FileTransfer(17969):at   org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl $ HttpsEngine.makeConnection(HttpsURLConnectionImpl.java:378)   11-19 13:56:13.339:E / FileTransfer(17969):at   org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)   11-19 13:56:13.339:E / FileTransfer(17969):at   org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:152)   11-19 13:56:13.339:E / FileTransfer(17969):at   org.apache.cordova.FileTransfer.download(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):at   org.apache.cordova.api.PluginManager $ 1.run(PluginManager.java:231)   11-19 13:56:13.339:E / FileTransfer(17969):at   java.lang.Thread.run(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 / FileTransfer(17969):at   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):at   org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:207)   11-19 13:56:13.339:E / FileTransfer(17969):at   java.security.cert.CertPathValidator.validate(CertPathValidator.java:197)   11-19 13:56:13.339:E / FileTransfer(17969):at   org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:156)   11-19 13:56:13.339:E / FileTransfer(17969):... 13 more

1 个答案:

答案 0 :(得分:4)

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

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

这是工作!!!谢谢Simon Mac Donald !!