在AFNetworking 2.0中使用SSL时出现错误1012

我正尝试使用SSL连接到我的网站,该网站使用了由StartSSL签名的authentication。 当我浏览到网站时,一切正常,但是,当我尝试在应用程序中使用SSL时,我得到:

Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn't be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x8d635f0 {NSErrorFailingURLKey=https://edutoets.nl/API/login.php, NSErrorFailingURLStringKey=https://edutoets.nl/API/login.php} 

我已经在应用程序包中包含了.cer格式的证书(在将它从.crt转换为.cer后),AFNetworking可以find它。 这是我创buildpipe理器安全策略的代码:

 - (AFSecurityPolicy*) sslSecurityPolicy { NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"edutoets" ofType:@"cer"]; NSData *certData = [NSData dataWithContentsOfFile:cerPath]; AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init]; [securityPolicy setAllowInvalidCertificates:NO]; [securityPolicy setPinnedCertificates:@[certData]]; [securityPolicy setSSLPinningMode:AFSSLPinningModeCertificate]; return securityPolicy; } 

在这里,我设置安全策略并执行请求:

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager; [manager setSecurityPolicy:[self dodyrwSecurityPolicy]]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; [manager POST:kLoginURL parameters:... success:...]; 

我不知道我在这里做错了什么。 .cer文件看起来很好(证书在浏览到网站时对应于证书)。 这发生在iOS模拟器上。

任何人都可以帮助我吗?

尽pipe在我的应用程序中embedded了有效的SSL证书,但我也遇到了类似的情况,即收到了错误1012。 当使用AFNetworking v1时,这个应用程序可以与服务器进行通信(其他一切保持不变)。 我的问题是由于没有在应用程序中embedded整个证书链而造成的。 设置validatesCertificateChain = NO; 解决了这个问题。

那么,显然你也应该添加你的中间证书和根证书到应用程序包。 我做到了,就开始工作了!

我修复了这个服务器端 – 我的服务器安装了一个.crt文件,它不包括所有的中间证书。 你可以把所有的证书放到一个.crt文件中,并安装到networking服务器上。

我不必以任何方式更改我的应用程序二进制文件。 (谢天谢地!)

(这个错误很奇怪,使用Safari或Chrome时HTTPS问题没有发生,这个错误代码是'用户取消authentication',但是这绝对是一个SSL问题。