AFNetworking 使用字签证证书访问HTTPS
把服务器给你的自签证的证书放入bundle一般是.cer文件
创建AFNetworking 安全策略对象,并设置发起请求manager的安全策略属性.设置了安全策略属性,AFNnetworking会自动扫描bundl里的证书.
-(void)SetAFSecurityPolicy:(AFHTTPRequestOperationManager *)manager
{
//使用bundle的证书,afnnetworking会自动扫描bundl里的证书. start
AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
//securityPolicy = [AFSecurityPolicy defaultPolicy];
securityPolicy.allowInvalidCertificates = YES;
securityPolicy.validatesDomainName = NO;
manager.securityPolicy = securityPolicy;
//end
}
最坑的是 iOS9新出的App Transport Security 也就是要我们把所有请求从 HTTP改成HTTPS的家伙, 它竟然不认自签证的证书. 苹果大爷难道真是土豪惯了,以为我们开发者都会买CA的证书吗. 解决办法就是那里还是要设置在Info.plist中添加NSAppTransportSecurity类型Dictionary在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型 Boolean,值设为YES