美文网首页
https - In order to validate a d

https - In order to validate a d

作者: 小和大大 | 来源:发表于2018-08-13 09:29 被阅读0次

In order to validate a domain name for self signed certificates, you MUST use pinning,AFNetWorking使用自签证书时出现问题。

上述问题的解决方法:

//如果是需要验证自建证书,需要设置为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

相关文章

网友评论

      本文标题:https - In order to validate a d

      本文链接:https://www.haomeiwen.com/subject/varybftx.html