简体   繁体   中英

How can I download files from an https URI in android phonegap application?

how to download files with https protocol in android ? I'm try to use it, but keep getting an error.

My download code:

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

My log

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: Trust anchor for certification path not found. 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): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 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(Native Method) 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 more 11-19 13:56:13.339: E/FileTransfer(17969): Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. 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

Answer is change old cordova to cordova 2.2.0 and write in the code true, some 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);

And this is work!!! Thanks Simon Mac Donald!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM