使用HTTPS协议的Phonegap Cordova文件传输

时间:2016-11-16 17:24:43

标签: jquery cordova mobile https phonegap-pushplugin

我正在使用Phonegap 6.3.3。我必须下载一个文件。如果我的端点是HTTP连接,则操作正常,但如果端点使用HTTPS(TLS 1.2)连接fileTransfer.download则返回error.code = 3

    getDocumentFile : function(docId, fileName,successClb,errorClb){
        var url = this.endpoint + "/contents/getDocument?documentId=" + docId;
        var filePath = cordova.file.externalDataDirectory + fileName;

        var fileTransfer = new FileTransfer();
        fileTransfer.download(
                    url,
                    filePath,
                    function(entry) {                           
                        successClb(entry.nativeURL);
                    },
                    function(error) {
                        console.log("download error source " + error.source);
                        console.log("download error target " + error.target);
                        console.log("upload error code" + error.code);
                        errorClb(error);
                    },
                    false
                );

使用HTTPS协议使用Jquery调用ajax调用我没有任何问题。 你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。 正确跟随对证书自动签名(不可信)的HTTPS的正确调用。将 true 传递给倒数第二个参数(allowAllHost)非常重要。有关详细信息,请阅读reference cordova

new FileTransfer();
        fileTransfer.download(
                    url,
                    filePath,
                    success,
                    error,
                    true
                );