gpt4 book ai didi

ios - NSURLSession didReceiveChallenge 多个证书

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:26:55 26 4
gpt4 key购买 nike

如何根据服务器指定多个证书?在 session:didReceiveChallenge 方法中,我可以返回一个 NSURLCredential,但我没有找到一种方法来识别挑战来自哪个 URL。

我想做这样的事情:

-(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);
}

最佳答案

我终于找到了答案,你可以像这样获取NSURLAuthenticationChallenge的宿主:

NSString* host = challenge.protectionSpace.host;

就是这样

关于ios - NSURLSession didReceiveChallenge 多个证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40819385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com