【问题标题】:Sending Request to IIS from Phonegap (SSL/TLS) error从 Phonegap (SSL/TLS) 错误向 IIS 发送请求
【发布时间】:2013-07-17 11:23:24
【问题描述】:

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

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

任何帮助将不胜感激。

问候, 苏拉杰

【问题讨论】:

    标签: ios objective-c cordova ssl-certificate


    【解决方案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?

    【讨论】:

    • 嗨,Jageen,感谢您的帮助。我会试试这个代码,如果有问题,我会告诉你更新。
    猜你喜欢
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 2021-01-14
    相关资源
    最近更新 更多