Ios CFNetwork SSLHandshake使用AFNetworking 2.0、自签名cer和[policy setAllowInvalidCertificates:YES]失败 我用的是AF2 我的项目包中有一个自签名根CA证书 我允许具有以下内容的无效证书:[policy setAllowInvalidCertificates:YES] 我的url是https://
因此,从理论上讲,应该接受自签名证书 AFSecurityPolicyIos CFNetwork SSLHandshake使用AFNetworking 2.0、自签名cer和[policy setAllowInvalidCertificates:YES]失败 我用的是AF2 我的项目包中有一个自签名根CA证书 我允许具有以下内容的无效证书:[policy setAllowInvalidCertificates:YES] 我的url是https://,ios,ssl-certificate,afnetworking-2,cfnetwork,Ios,Ssl Certificate,Afnetworking 2,Cfnetwork,因此,从理论上讲,应该接受自签名证书 AFSecurityPolicy AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; [policy setAllowInvalidCertificates:YES]; AFHTTPRequestOperationManager AFHTTPRequestOperationManager *manager = [AFHTTPReq
AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
[policy setAllowInvalidCertificates:YES];
AFHTTPRequestOperationManager
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
[manager setRequestSerializer:[AFJSONRequestSerializer serializer]];
[manager setSecurityPolicy:policy];
[manager POST:url
parameters:dictionary
success:^(AFHTTPRequestOperation *operation, id responseObject) {
// Process Response Object
NSLog(@"JSON: %@", [responseObject description]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// Handle Error
NSLog(@"Failure Error: %@", [error description]);
}];
所以没有什么明显的错误
我的日志:
2014-04-10 15:05:40.412 https_AF2[5548:3607] CFNetwork SSLHandshake failed (-9800)
2014-04-10 15:05:41.092 https_AF2[5548:3607] CFNetwork SSLHandshake failed (-9800)
2014-04-10 15:05:41.732 https_AF2[5548:3607] CFNetwork SSLHandshake failed (-9800)
2014-04-10 15:05:41.734 https_AF2[5548:3607] NSURLConnection/CFURLConnection HTTP load failed
(kCFStreamErrorDomainSSL, -9800)
2014-04-10 15:05:41.736 https_AF2[5548:60b] Failure Error: Error Domain=NSURLErrorDomain
Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made."
UserInfo=0x8d6af80
{NSErrorFailingURLStringKey=https://(myUrl)/userLogin,
NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?,
NSErrorFailingURLKey=https://(myUrl)/userLogin,
NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made.,
NSUnderlyingError=0x8cb4920 "An SSL error has occurred and a secure connection to the server cannot be made."}
我能想象的唯一原因是服务器没有正确配置
任何解决这个问题的想法都将是伟大的 AFSecurityPolicy,能否尝试将validate DomainName也设置为NO
policy.validatesDomainName = NO;
我知道问题是什么。最后,问题不在iOS代码中。问题出在给我的url上 URL中的一个小改动解决了所有问题 发件人:
到 就这么简单 我不会删除这个问题,因为将来可能有人也会遇到同样的问题