1

I'm working with Phonegap 6.3.3. I have to download a file. If my endpoint is a HTTP connection the operation is ok, but if endpoint use a HTTPS (TLS 1.2) connection fileTransfer.download return 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
                );

Usign ajax call with Jquery with HTTPS protocol I have not any problem. Can you help me please?

Michel Foucault
  • 1,724
  • 3
  • 25
  • 48
  • 1
    On which platforms is this happening ? Did you install cordova-plugin-whitelist plugin ? – Hristo Eftimov Nov 16 '16 at 21:13
  • Android platform. I do not use whitelist plugin. How configure it? – Michel Foucault Nov 16 '16 at 23:07
  • You need to install the whitelist plugin and to config your config.xml file. Please check and the following stackoverflow post: http://stackoverflow.com/questions/29757593/ajax-command-to-request-url-no-longer-working. Write if you have any issues – Hristo Eftimov Nov 17 '16 at 08:16
  • Sorry I used whitelist plugin my config.xml contains following directives: – Michel Foucault Nov 17 '16 at 09:11
  • the first directive should be , not . The star (*) is missing. – Hristo Eftimov Nov 17 '16 at 09:39
  • Sorry, I don't understand. My first directive is: , it's not correct? – Michel Foucault Nov 17 '16 at 09:44
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/128332/discussion-between-xristoeftimov-and-michel-foucault). – Hristo Eftimov Nov 17 '16 at 09:51
  • the error object of filetransfer.download is following: {"code":3,"source":"https://192.168.250.155:8443/chp_backend/volantini/contents‌​/getDocument?documentId=2108","target":"file:///storage/emulated/0/Android/data/c‌​om.fly.app/files/file.pdf","http_status":null,"body":null,"exception":"java.security.cert.Cer‌​tPathValidatorException: Trust anchor for certification path not found."}" – Michel Foucault Nov 17 '16 at 10:23

1 Answers1

1

I've found the solution. The correct call for HTTPS with certificate auto signed (not trusted) is following. It is important passing true to penultimate parameter (allowAllHost). For more information you read the reference cordova

new FileTransfer();
        fileTransfer.download(
                    url,
                    filePath,
                    success,
                    error,
                    true
                );
Michel Foucault
  • 1,724
  • 3
  • 25
  • 48