使用https进行NSURLConnection

时间:2013-12-03 13:00:55

标签: ios https nsurlconnection

如果证书是可信的,我必须使用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];

    }

}

0 个答案:

没有答案