0

我在 IIS 上托管了 asp.net 站点(https)。我在 Mac 机器(适用于 iOS)上的 phonegap 应用程序位于同一个本地网络中。该网站充当此 phonegap 应用程序请求的处理程序,但我无法调试(即向本地网络中的机器托管网站发送请求)。我不认为这是外部 URL 或白名单问题,但它似乎是 SSL/TLS 问题,由于此证书错误,它无法继续。

如何解决这个问题,请帮忙。我不熟悉目标C环境。有关如何解决此问题的任何想法。

任何帮助将不胜感激。

问候, 苏拉杰

4

1 回答 1

1

您必须处理 NSURLConnection 委托,因为您的域是本地的,您的应用程序不信任您的证书。此代码将帮助您接受任何证书。

- (BOOL)connection:(NSURLConnection *)conn canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
        // A delegate method called by the NSURLConnection when something happens with the
        // connection security-wise.
        {
            NSLog(@"%@",protectionSpace.authenticationMethod);
            return YES;
        }   

        // Called if the HTTP request receives an authentication challenge.
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
            if([challenge previousFailureCount] == 0) {
                NSURLCredential *newCredential;
                newCredential=[NSURLCredential credentialWithUser:self.username password:self.password persistence:NSURLCredentialPersistenceNone];
                [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
            } else {
                [[challenge sender] cancelAuthenticationChallenge:challenge];
            }
        }



或使用此参考
How to use NSURLConnection to connect with SSL for an untrusted cert?

于 2013-07-17T11:57:12.897 回答