https验证的代码块

2017-03-30  本文已影响11人  Archer_S

没错,博主又来写防忘文了,直接贴上一段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;
}

博主还在学习......未完待续......

上一篇下一篇

猜你喜欢

热点阅读