How to download file from secure server using dependency service

Hi,
I created a dependency service "downloadFileManager".
In Droid i implemented this function :

public void DownloadFile(string uri, string filename)
{
    var cookies = GetCookies();
  Android.Net.Uri contentUri = Android.Net.Uri.Parse(uri);

  var deviceIdentifier = new DeviceHelper();
  deviceIdentifier.GetIdentifier();

  Android.App.DownloadManager.Request r = new Android.App.DownloadManager.Request(contentUri);

  r.AddRequestHeader("Accept", "*/*");
  r.AddRequestHeader("Accept-Encoding", "gzip, deflate, sdch, br");
  r.AddRequestHeader("Uuid", deviceIdentifier.GetIdentifier());

  foreach (var cookie in cookies)
  {
    r.AddRequestHeader("Cookie", cookie);
  }

  r.SetDestinationInExternalPublicDir(Android.OS.Environment.DirectoryDownloads, filename);

  r.AllowScanningByMediaScanner();

  r.SetNotificationVisibility(Android.App.DownloadVisibility.VisibleNotifyCompleted);

  Android.App.DownloadManager dm = (Android.App.DownloadManager)Forms.Context.GetSystemService(Context.DownloadService);

  dm.Enqueue(r);
}

When i try to download a file from demo site like "http://www.pdf995.com/samples/pdf.pdf" the download works fine but when i try to download from my (secured) server the download "unsucessful" and in the iis log i see that the request get "401" error.

I checked the request and got the session cookie.

What did i miss??

Thank you.

Answers

Sign In or Register to comment.