允许与AFNetworking无效的证书

我一直在使用下面的代码

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request]; operation.allowsInvalidSSLCertificate=YES; 

现在我已经将AFNetworking更改为最新版本2.0。 operation.allowsInvalidSSLCertificate不再适用于AFHTTPRequestOperation 。 根据我使用的文件

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.securityPolicy.allowInvalidCertificates = YES; 

和我的请求代码是

 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog (@"success: %@", operation.responseString); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error: %@", error.description); } ]; [operation start]; [operation waitUntilFinished]; 

但是这不适用于需要证书的HTTPS。 我该怎么做才能做到这一点?

我通过在[操作开始]之前添加下面的代码解决了这个问题

 AFSecurityPolicy *sec=[[AFSecurityPolicy alloc] init]; [sec setAllowInvalidCertificates:YES]; operation.securityPolicy=sec; 

发生这种情况是因为AFHTTPRequestOperationManager未连接到AFHTTPRequestOperation 。 所以设置pipe理者的安全证书不能在请求操作中施加魔法。 所以必须初始化并赋值给AFHTTPRequestOperation

希望这有助于某人:)

我所知道的。 这是一个iOS 7的问题。 Apple不允许与自签名证书网站进行通信。 除非您将证书发送到设备并添加为可信证书列表。

支持其他问题的评论: https : //stackoverflow.com/a/20251011/753603

找不到由Apple提供的文件。