For iOS, I have written a custom delegate and implementation of NSUrlSession
. It is working fine for Http urls. But when I try to download image resources from a HTTPS source that has been authenticated and which require a Cookie to be passed, the download fails with a NSUrlErrorCode
-1013 or -1002.
NSMutableUrlRequest req = new NSMutableUrlRequest(new NSUrl(uri.ToString()));
req.Headers = dictHeaders;//
NSUrlSessionDownloadTask newTask = session.CreateDownloadTask(req);
activeDownloads.Add(newTask);
newTask.Resume();
So in the NSUrlSessionDownloadDelegate
I have implemented the DidReceiveChallenge
method but am not passing anything there currently because I want to pass the cookie from my initial login as above.
NSUrlSession
uses shared session for the complete app but my initial login API is done using RestSharp.RestClient
which fetches the cookie that I can use throughout the app.
So my question is how do I pass the cookie to NSUrlSession
?