這裏介紹在AFNetworking中要使用https請求,導入證書的作法:
1.文件導入:
項目中須要導入後綴爲.cer的證書,該證書由後臺服務器根據HTTPS的要求生成
2.AFNetworking中的設置:服務器
/**** SSL Pinning ****/ [_manager setSecurityPolicy:[Public customSecurityPolicy]]; /**** SSL Pinning ****/
3.customSecurityPolicy方法:code
+ (AFSecurityPolicy *)customSecurityPolicy { /**** SSL Pinning ****/ NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"communityFinancial" ofType:@"der"]; if (cerPath == nil) { NS_APPDebugLog(@"***文件路徑沒找到"); } NSData *certData = [NSData dataWithContentsOfFile:cerPath]; AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; // 自簽名證書設爲YES 生產X.509證書設置爲NO [securityPolicy setAllowInvalidCertificates:YES]; [securityPolicy setPinnedCertificates:@[certData]]; /**** SSL Pinning ****/ return securityPolicy; } ----------