AFNetworking2.x https 常用代码

- (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) {
//注释同上
}];
posted @ 2016-01-19 10:10  李伯波  阅读(299)  评论(0编辑  收藏  举报