每次收到每个 https 请求的响应后,我都需要删除 NSURLCredential 存储。在我的情况下没有发生这种情况。下面的方法只在第一次请求时执行,对于下一次请求它不会被调用。当我重新启动应用程序时,它会被调用。我在 SO 中尝试了很多建议,但没有帮助。我怎样才能解决这个问题?
- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
SecTrustRef trust = challenge.protectionSpace.serverTrust;
NSURLCredential *cred;
cred = [NSURLCredential credentialForTrust:trust];
[challenge.sender useCredential:cred forAuthenticationChallenge:challenge];
}