ここで、-connection:didReceiveAuthenticationChallenge:関数を使用してSSL証明書を確認します。ユーザーの要求に基づいて、私はすべての要求をチェックする必要があります。しかし、私のテストデモでは、-connection:didReceiveAuthenticationChallenge:デリゲート関数は5分に1回だけ呼び出されます。5分後、再度呼び出されます。ただし、ユーザーは5分以内に複数のリクエストを送信する場合があります。この問題を解決しなければならないことを知っている人はいますか?
リクエストコード
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:_server_url]];
[urlRequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[query dataUsingEncoding:NSUTF8StringEncoding]];
urlConnection = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease] ;
[urlConnection scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
[urlConnection start];
委任機能:
- (BOOL)connection:(NSURLConnection *)conn canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
NSLog(@"authenticate method:%@",protectionSpace.authenticationMethod);
return YES;
}
- (void) connection:(NSURLConnection *)conn didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSURLAuthenticationChallenge *_challenge=[challenge retain];
SecTrustRef trustRef = [[_challenge protectionSpace] serverTrust];
SecTrustEvaluate(trustRef, NULL);
SecCertificateRef certRef = SecTrustGetCertificateAtIndex(trustRef, 0);
NSData *certificateData = (NSData *) SecCertificateCopyData(certRef);
const unsigned char *certificateDataBytes = (const unsigned char *)[certificateData bytes];
X509 *certificateX509 = d2i_X509(NULL, &certificateDataBytes, [certificateData length]);
NSString *subject = CertificateGetDomainName(certificateX509);
NSLog(@"Subject: %@", subject);
[[_challenge sender] continueWithoutCredentialForAuthenticationChallenge:_challenge];
}