在iOS 10.2中,当我们尝试与几个不同的api进行通信时,我们发现了这个错误。奇怪的是,我们有时只会在同一个网址的200个请求中有2个进行此操作。但另一方面,我有时可以做3000次api通话,但没有看到问题。
据我所知,这与ATS有关。输出还告诉我们,我们得到一个与ATS相关的错误代码:kCFStreamErrorCodeKey = -9806。
但是我不明白这与ATS有什么关系,因为有几点:
我打电话的网址是https。
服务器具有有效的TLSv1.2证书
我试图创建一个例外,但它似乎没有做任何事情
我们尝试以不同的方式创建异常,既允许任意加载,又为域创建异常。
即使在服务器具有有效证书时不需要,我们也尝试创建例外
这就是我们为域创建例外的方式。
NSAppTransportSecurity
NSExceptionDomains
NSIncludesSubdomains
NSTemporaryExceptionAllowsInsecureHTTPLoads
NSTemporaryExceptionMinimumTLSVersion
TLSv1.2
NSTemporaryExceptionRequiresForwardSecrecy
这就是我们启用仲裁负载的方式:
NSAppTransportSecurity
NSAllowsArbitraryLoads
另一个奇怪的是,我们只是在iOS 10(10.2)中看到这个。当我们在iOS 9.3中进行测试时,一切都按预期工作。
我已经制作了一个示例应用程序来重现这个。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self Perform];
}
int i = 0;
- (void) Perform
{
NSURLSessionConfiguration *defaultConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *sessionWithoutADelegate = [NSURLSession sessionWithConfiguration:defaultConfiguration];
NSURL *url = [NSURL URLWithString:(@"/chart/0/tracks")];
[[sessionWithoutADelegate dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if(error != NULL)
{
NSLog(@"Got response with error %@.\n", error);
}
NSLog(@"%d",i);
i++;
if(i <1000)
{
[self Perform];
}
}] resume];
}
有人对解决方案有所了解吗?感谢
如果觉得《网页无法与服务器建立安全连接失败 “发生了SSL错误 无法与服务器建立安全连接。”...》对你有帮助,请点赞、收藏,并留下你的观点哦!