我需要使用私有(private) HTTPS API,而客户端在主机上的证书不正确。 证书适用于 www.clienthost.com,我正在使用 api.clienthost.com。 所以我需要通过 HTTPS 连接到 api.clienthost.com,忽略不正确的证书,但仍然确保它是 www.clienthost.com 的证书,而不是其他证书。 我找到了这个答案:How to use NSURLConnection to connect with SSL for an untrusted cert?它似乎解决了我一半的问题,但我想弄清楚如何仍然检查主机证书是否是我希望看到的,并且没有什么不同。
最佳答案
尝试实现 NSURLConnection 的委托(delegate)方法
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
那么下面会包含主机
[[challenge protectionSpace] host]
然后您可以通过调用以下方法之一继续操作
continueWithoutCredentialForAuthenticationChallenge:
cancelAuthenticationChallenge:
useCredential:forAuthenticationChallenge:
关于iphone - 如何让 iPhone 应用程序接受不正确的服务器证书但只接受特定的服务器证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2675782/