https - In order to validate a d

2018-08-13  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读