繁体   English   中英

NSURLConnection与https

[英]NSURLConnection with https

如果证书受信任,我必须使用https来实现NSURLConnection,然后如果证书不受信任,则连接应该可以正常进行,然后我必须从用户那里获得确认。 我该如何实施?

我的代码

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 
{
    self.mHTTPLAuthenticationChallenge = challenge;
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
    {


        NSString *theErrorMSG = [[NSString alloc]initWithFormat:@"The certificate for this server is invalid. You might be connecting to a server that is pretending to be \“%@\” which could put your confidential information at risk.",challenge.protectionSpace.host];

        UIAlertView *theAlertView = [[UIAlertView alloc]initWithTitle:kAppName message:[ARCUtilities ARCLocalizedString:theErrorMSG] delegate:self cancelButtonTitle:[ARCUtilities ARCLocalizedString:@"Continue"] otherButtonTitles:[ARCUtilities ARCLocalizedString:@"Cancel"], nil];
        [theErrorMSG release];

        [theAlertView show];
        [theAlertView release];
         [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];

    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM