码迷,mamicode.com
首页 > Web开发 > 详细

AFNetworking2.x https 常用代码

时间:2016-01-19 10:31:39      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

- (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) {
//注释同上
}];

AFNetworking2.x https 常用代码

标签:

原文地址:http://www.cnblogs.com/li-baibo/p/5141312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!