同期リクエストを送信しようとすると、以下のエラーが発生しました。
エラー Domain=NSURLErrorDomain Code=-1202 「このサーバーの証明書は無効です。「xx.xxxx.com」になりすましたサーバーに接続している可能性があり、機密情報が危険にさらされる可能性があります。」
以下のコードを見つけてください
NSURL *url=[[NSURL alloc]initWithString:strURL];
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:url];
[url release];
[request setTimeoutInterval:90];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:dataForChallenge];
[request setValue:@"application/json" forHTTPHeaderField:@"content-type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSURLResponse *resp = nil;
NSError *err = nil;
NSData *response = [NSURLConnection sendSynchronousRequest: request returningResponse: &resp error: &err];
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
// NSLog(@"selector : %@",NSStringFromSelector(_cmd));
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
{
// NSLog(@"selector 1: %@",NSStringFromSelector(_cmd));
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
// NSLog(@"selector : %@",NSStringFromSelector(_cmd));
if( [[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust] )
{
// NSLog(@"selector 1: %@",NSStringFromSelector(_cmd));
return YES;
}
return NO;
}
上記の 2 つのメソッドは呼び出されません。私の場合、同期要求のみを送信する必要があります。
以下の行を使用しましたが、正常に動作しますが、AppStore は私のアプリを拒否しました:
[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
どうすればこれを修正できますか?