没错,博主又来写防忘文了,直接贴上一段https验证的代码
+ (AFSecurityPolicy*)customSecurityPolicy {
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
NSData *certData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"XXXXHttps" ofType:@"cer"]];
NSSet *cerSet = [NSSet setWithObject:certData];
securityPolicy.allowInvalidCertificates = YES;
[securityPolicy setValidatesDomainName:NO];
if(certData){
[securityPolicy setPinnedCertificates:cerSet];
}
return securityPolicy;
}
博主还在学习......未完待续......
网友评论