在AFNetworking 2.0中使用SSL时出现错误1012 [英] Error 1012 when using SSL in AFNetworking 2.0

查看:263
本文介绍了在AFNetworking 2.0中使用SSL时出现错误1012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用SSL连接到我使用由StartSSL签署的证书的网站。当我浏览网站,一切工作正常,但是,当我尝试使用SSL在应用程序,我得到:

I'm trying to connect with SSL to my website which is using a certificated signed by StartSSL. When I browse to the website, everything is working fine, however, when I try to use SSL in the app, I get:

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}

格式(在将.crt转换为.cer与openssl)在应用程序包和AFNetworking可以找到它。这是我的代码,创建经理的安全策略:

I've included the certificate in .cer format (after converting it from .crt to .cer with openssl) in the app bundle and AFNetworking can find it. Here's my code that creates the security policy of the manager:

- (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;
}



此处我设置安全策略并执行请求:

And here I set the security policy and execute the request:

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

我不知道我在这里做错了什么。 .cer文件看起来不错(证书对应于浏览网站时的证书)。

I don't know what I'm doing wrong here. The .cer file looks fine (the certificate corresponds to the certificate when browsing to the website). This is happening on the iOS simulator.

任何人都可以帮我解决这个问题。

Could anyone help me with this?

推荐答案

好吧,你也应该添加您的中间证书和根证书到应用程序包。 Afer我做到了,它开始工作了!

Well, apparently you should also add your intermediate certificate and root certificate to the app bundle. Afer I did that, it started to work!

这篇关于在AFNetworking 2.0中使用SSL时出现错误1012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆