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;
}
複製代碼

 

 而後在管理器裏這麼設置css

 

 

複製代碼
 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) {
//註釋同上
}];
相關文章
相關標籤/搜索