0

安全な安らかなサービスからデータを取得しようとしています。私は他の多くの投稿をフォローしています

NSURLConnection を使用して、信頼されていない証明書の SSL に接続する方法は?

しかし、私の場合、didReceiveAuthenticationChallenge と canAuthenticateAgainstProtectionSpace は呼び出されません。

問題を解決できるか、安全な安らかなサービスと呼ぶための良い例を教えてください。

 NSURL *url = [NSURL URLWithString:@"https://76.69.53.126:8443/jaxrs/tdgateway/getCountries"];


NSError * error = nil;   
NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];
[ NSURLConnection sendSynchronousRequest: urlRequest returningResponse: nil error: &error ];

NSLog(@"This is %@",url);




- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    NSLog(@"This is canAuthenticateAgainstProtectionSpace");
    return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    NSLog(@"This is didReceiveAuthenticationChallenge");
    [[challenge sender] cancelAuthenticationChallenge:challenge];
}  
4

2 に答える 2

0

とは異なる可能性があるNSURLAuthenticationMethodServerTrustため、これを試して開始してください。

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {
    return YES;
}

すぐにキャンセルしないでください。

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    NSLog(@"This is didReceiveAuthenticationChallenge");
    [[challenge sender] cancelAuthenticationChallenge:challenge];
}  
于 2012-07-03T14:56:59.987 に答える