4

我想使用自签名证书将我的 iOS 应用与 AFNetwork 连接到我的网络服务器。我在 github 上找到了一个解决方案(https://github.com/AFNetworking/AFNetworking/pull/694)我试了一下,证书固定似乎有效,但我遇到了另一个错误:

错误域 = NSURLErrorDomain 代码 = -1012 “操作无法完成。(NSURLErrorDomain 错误 -1012。)” UserInfo = 0x7bc2090 {NSErrorFailingURLKey =(我的域)}

有人知道这个错误是否与 AFNetworking 框架和自签名证书有关吗?

已解决: 我找到了错误的解决方案。我必须将 SSLPinningMode 设置为 AFSSLPinningModeCertificate 现在它可以工作了。

AFJSONRequestOperation *operation =[AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSDictionary *resDictionary = (NSDictionary *)JSON;
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
    NSLog(@"%@",error);
}];
operation.SSLPinningMode = AFSSLPinningModeCertificate;
[operation start];
4

1 回答 1

0

试试这个解决方法。

AFJSONRequestOperation *operation =[AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
    NSDictionary *resDictionary = (NSDictionary *)JSON;
}
                                                                                   failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
                                                                                       NSLog(@"%@",error);
                                                                                   }];
operation.securityPolicy.allowInvalidCertificates = YES;
[operation start];
于 2013-10-10T12:51:20.997 回答