单向验证,不需要证书在本地
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//或者 AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = YES;
securityPolicy.validatesDomainName = NO;
manager.securityPolicy = securityPolicy;
双向验证,需要证书放在本地
ps:找服务端要证书~
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//或者 AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"证书名" ofType:@"cer"];
NSData *data = [NSData dataWithContentsOfFile:cerPath];
NSArray *cerArray = @[data];
securityPolicy.allowInvalidCertificates = YES;
securityPolicy.validatesDomainName = YES;
[securityPolicy setPinnedCertificates:cerArray];
manager.securityPolicy = securityPolicy;