上述问题的解决方法:
//如果是需要验证自建证书,需要设置为YES
securityPoliy.allowInvalidCertificates = YES;
securityPoliy.validatesDomainName = NO;//不验证证书的域名
HTTPS步骤:
1.从服务器要来 .crt格式的证书,然后用Mac钥匙串打开,然后导出 .cer格式的证书
2.把 .cer证书导入程序的 NSBundle中。
验证证书的代码:
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];
[dxClient setSecurityPolicy:securityPoliy];
转自:https://www.cnblogs.com/Crazy-ZY/p/6094383.html
网友评论