ios - 从 Phonegap (SSL/TLS) 错误向 IIS 发送请求

标签 ios objective-c cordova ssl-certificate

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

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

如有任何帮助,我们将不胜感激。

问候, 苏拉杰

最佳答案

您必须处理 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?

关于ios - 从 Phonegap (SSL/TLS) 错误向 IIS 发送请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17698512/

相关文章:

iphone - 如果我使用自定义 UITableViewCell,是否需要设置 heightForRowAtIndexPath?

iphone - UIKit 不释放 Controller ,如果它不与动画一起删除?

ios - Xcode 6.4 : OS X and iOS Targets, Cordova

iphone - phonegap 2.6 iOS 程序中出现意外的 '@'

android - 在 Samsung Galaxy S6 和 S6 Edge 上找不到人行横道项目服务

objective-c - 是否可以在 ios 中添加注释但不更改 map View 区域

ios - 当 iOS 应用程序在 Xamarin 中作为后台时,如何通知我蓝牙连接?

ios - 如何解决flutter中的iOS部署目标问题

ios - 离线计量iOS应用程序中的音频文件

ios - 是否可以从 QLPreviewController 中删除导航栏