Reputation: 310
I require to download files using HTTPS, but it seems that standard DownloadManager doesn't support HTTPS, only Http.
I've made some resarch and found just one topic about it, but it doesn't help me too much. alvinsj from that topic(https://github.com/alvinsj/android-https-downloadmanager-demo) suggesed a solution where he just amended the check in source code:
if (scheme == null || !(scheme.equals("http") ||scheme.equals("https"))) {
throw new IllegalArgumentException("Can only download HTTP URIs: " + uri);
}
It looks not correct to me because even though it would work it will not be sequre. I really need your help! Some examples, thoughts will be much appreciated!
Thanks
Upvotes: 4
Views: 2346
Reputation: 310
I found the answer - it was quite simple. We tuned our server to use Base64 authentication, so i just had to set a requestHeader for my request:
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
StringBuilder header = new StringBuilder().append("Basic ");
Pair<String, String> serverCredentials = getServerCredentials();
if (!serverCredentials.first.isEmpty()) {
try {
header.append(EncryptionUtils.toBase64fromString(new StringBuilder().append(serverCredentials.first)
.append(":").append(serverCredentials.second).toString()));
request.addRequestHeader("Authorization", header.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 3
Reputation: 3322
[blog]: Accepting a certificate for HTTPs on Android it may be useful to you While downloading from https you need to trust all ssl certificates.
Upvotes: -1