通过 https 连接并下载文件 ionic3

Connect via https and download file ionic3

这是一种通过 https 连接到服务器并下载文件的方法吗?我正在使用 File Transfer 但我无法进行身份验证。 (使用wget我可以访问)

这是一个尝试:

let url = "https://0.0.0.0:0000/maps/"+element['file'];
                  this.fileTransfer = this.transfer.create();
                  this.fileTransfer.download(url, res.nativeURL+""+element['file']).then((entry) => {
                    console.log('download complete: ' + entry.toURL());
                  }, (error) => {
                    console.log(error);
                  });

这个url不是我真正的url,只是为了给你看。任何的想法? 我必须输入用户名和密码。就像 api 中的 header 追加。

根据 Ionic 3 文档,您可以使用 headers 下载功能。

https://ionicframework.com/docs/native/file-transfer/#download

download(source, target, trustAllHosts, Optional)

Param | Type | Details

Optional | object | parameters, currently only supports headers (such as Authorization (Basic Authentication), etc).

示例:

let options = {
    headers: {
        "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=="
    }
}

this.fileTransfer.download(url, res.nativeURL + "" + element['file'], false, options).then((entry) => {
    console.log('download complete: ' + entry.toURL());
}, (error) => {
    console.log(error);
});