gpt4 book ai didi

objective-c - 使用 NSURLConnection 处理自签名证书

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:42 24 4
gpt4 key购买 nike

我想允许带有 NSURLConnection 的自签名证书,前提是主机在受信任的列表中。

我看到很多人在做这样的事情:

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
if (allowSelfSignedCertForThisHost) {
NSLog(@"Allowing self signed!");
return YES;
}
}
return NO;
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
if ([trustedHosts containsObject:challenge.protectionSpace.host]) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}

但是,我想知道为什么您要调用 useCredential:forAuthenticationChallenge 之后还要调用 continueWithoutCredentialForAuthenticationChallenge

最佳答案

只需使用 iPhone 配置实用程序Apple Configurator 在设备上添加该证书。

关于objective-c - 使用 NSURLConnection 处理自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21179044/

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