0
如何根据服务器指定多个证书? 在session:didReceiveChallenge
方法中,我可以返回一个NSURLCredential,但我没有找到一种方法来确定挑战来自哪个URL。NSURLSession didReceiveChallenge多个证书
我想要做的做这样的事情:
-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
// get the certificate depending on the url
NSString *certificatePath;
if ([url isEqualToString: @"server1.com"]) {
certificatePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/server1.p12"];
} else if ([url isEqualToString: @"server2.com"]) {
certificatePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/server2.p12"];
}
//... some certificate stuff
NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity certificates:(__bridge NSArray*)certsArray persistence:NSURLCredentialPersistencePermanent];
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}
'如果(url === @“server1.com”)',你的意思是http://stackoverflow.com/questions/8239274/url-host-comparison? – Larme
是的,这只是一个例子 –