iOS关于配置https的请求代码

NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"test"ofType:@"cer"];

NSData *cerData = [NSData dataWithContentsOfFile:cerPath];

NSSet *cerSet = [[NSSet alloc] initWithObjects:cerData,nil];

AFSecurityPolicy *securityPoliy = [AFSecurityPolicy defaultPolicy];

//allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO

//如果是需要验证自建证书,需要设置为YES

securityPoliy.allowInvalidCertificates =YES;

securityPoliy.validatesDomainName =NO;

//设置证书

[securityPoliy setPinnedCertificates:cerSet];

[manager setSecurityPolicy:securityPoliy];
```

你可能感兴趣的:(iOS关于配置https的请求代码)