Re: Questions on when credentials are used in NSURLSessionDownloadTask
Re: Questions on when credentials are used in NSURLSessionDownloadTask
- Subject: Re: Questions on when credentials are used in NSURLSessionDownloadTask
- From: "Quinn \"The Eskimo!\"" <email@hidden>
- Date: Tue, 21 Apr 2015 09:51:19 +0100
> On 21 Apr 2015, at 03:28, Daryle Walker <email@hidden> wrote:
>
> When creating a credential with username “hello” and password “there,” the former URL succeeds (200) while the latter fails (401).
This works for me now, both in Safari and in code. Here's my challenge handler:
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler {
if ( [ @[ NSURLAuthenticationMethodDefault,
NSURLAuthenticationMethodHTTPBasic,
NSURLAuthenticationMethodHTTPDigest,
NSURLAuthenticationMethodNTLM
] containsObject:challenge.protectionSpace.authenticationMethod] ) {
completionHandler(
NSURLSessionAuthChallengeUseCredential,
[NSURLCredential credentialWithUser:@"hello" password:@"there" persistence:NSURLCredentialPersistenceForSession
]);
} else {
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
}
}
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden