标签:
- (AFSecurityPolicy*)customSecurityPolicy { /**** SSL Pinning ****/ NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"你的证书" ofType:@"cer"]; NSData *certData = [NSData dataWithContentsOfFile:cerPath]; AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init]; [securityPolicy setAllowInvalidCertificates:NO]; [securityPolicy setPinnedCertificates:@[certData]]; [securityPolicy setSSLPinningMode:AFSSLPinningModeCertificate]; /**** SSL Pinning ****/ return securityPolicy; }
然后在管理器里这么设置
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; /**** SSL Pinning ****/ [manager setSecurityPolicy:[self customSecurityPolicy]]; /**** SSL Pinning ****/ [manager GET:@"网站的url" parameters:params success:^(AFHTTPRequestOperation *operation, NSDictionary* responseObject) { //这里是你自己的代码了 } failure:^(AFHTTPRequestOperation *operation, NSError *error) { //注释同上 }];
标签:
原文地址:http://www.cnblogs.com/li-baibo/p/5141312.html