// 1.初始化单例类 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.securityPolicy.SSLPinningMode = AFSSLPinningModeCertificate; // 2.设置证书模式 NSString * cerPath = [[NSBundle mainBundle] pathForResource:@"xxx" ofType:@"cer"]; NSData * cerData = [NSData dataWithContentsOfFile:cerPath]; manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate withPinnedCertificates:[[NSSet alloc] initWithObjects:cerData, nil]]; manager.securityPolicy.allowInvalidCertificates = NO; [manager.securityPolicy setValidatesDomainName:YES];