2016-11-16 42 views
0

我正在使用Phonegap 6.3.3。我必須下載一個文件。如果我的終點是HTTP連接操作是好的,但如果端點使用HTTPS(TLS 1.2)連接fileTransfer.downloaderror.code = 3Phonegap使用HTTPS協議的Cordova文件傳輸

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

Usign Ajax調用使用jQuery與HTTPS協議我沒有任何問題。 你能幫我嗎?

+1

在哪些平臺上發生這種情況?你安裝了cordova-plugin-whitelist插件嗎? –

+0

Android平臺。我不使用白名單插件。如何配置它? –

+0

您需要安裝白名單插件並配置您的config.xml文件。請檢查和下面的stackoverflow帖子:http://stackoverflow.com/questions/29757593/ajax-command-to-request-url-no-longer-working。如果您有任何問題,請寫下 –

回答

0

我找到了解決方案。 正確調用帶有證書自動簽名(不可信)的證書的HTTPS如下。重要的是通過true倒數第二個參數(allowAllHost)。欲瞭解更多信息,請閱讀reference cordova

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