小说网 找小说 无限小说 烟雨红尘 幻想小说 酷文学 深夜书屋

AFNetworking 3.0+ 启用完整、严格的https证书较验参考代码

// 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];

posted on 2016-10-17 10:47  王峰炬  阅读(122)  评论(0编辑  收藏  举报

导航