使用证书.cer文件。在https请求中,保证数据的安全,防止中间人攻击和被网络监听
-
AFNetworking中的使用
设置HTTPSessionManager对象的securityPolicy属性 // 配置证书 NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"cf" ofType:@"cer"]; NSData *cerData = [NSData dataWithContentsOfFile:cerPath]; NSSet *cerSet = [[NSSet alloc] initWithObjects:cerData, nil]; AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModePublicKey]; securityPolicy.allowInvalidCertificates = YES; securityPolicy.validatesDomainName = NO; securityPolicy.pinnedCertificates = cerSet; manager.securityPolicy = securityPolicy
-
SDWebImage中的使用
重点是options: SDWebImageAllowInvalidSSLCertificates [imageView sd_setImageWithURL:[NSURL URLWithString:name] placeholderImage:[UIImage imageNamed:@"*.png"] options:SDWebImageAllowInvalidSSLCertificates];
-
问题
设置好后,遇到请求失败的问题finished with error - code: -999 彻底退出Charles即可
网友评论