【问题标题】:NSURLSession getting intermittent SSLHandshake failed (-9810) errorNSURLSession 间歇性 SSLHandshake failed (-9810) 错误
【发布时间】:2014-01-06 16:30:45
【问题描述】:

从安全墙后面的安全 URL 下载图像。像https://foo.com/bar.png这样的网址

有时我会收到 SSLHandshake 错误。有时错误只发生一次,但有时错误是恒定的,我无法下载文件。

DownloadImageApp[2914] <Warning>: CHALLENGE!!! (NSURLAuthenticationMethodServerTrust)
DownloadImageApp[2914] <Warning>:    server = foo.com
DownloadImageApp[2914] <Warning>: CFNetwork SSLHandshake failed (-9810)
DownloadImageApp[2914] <Warning>: CHALLENGE!!! (NSURLAuthenticationMethodServerTrust)
DownloadImageApp[2914] <Warning>:    server = foo.com
DownloadImageApp[2914] <Warning>: CHALLENGE!!! (NSURLAuthenticationMethodNTLM)
DownloadImageApp[2914] <Warning>:    NSURLAuthenticationMethodNTLM

我使用以下代码来处理挑战

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler {
    NSLog(@"CHALLENGE!!! (%@)", challenge.protectionSpace.authenticationMethod);

    if (challenge.error)
        NSLog(@"  -- error: %@", challenge.error.description);
    if (challenge.previousFailureCount > 0)
        NSLog(@"  -- previous failure count = %d", challenge.previousFailureCount);
    if (challenge.proposedCredential)
        NSLog(@"  -- proposed credential user: %@", challenge.proposedCredential.user);

    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        NSLog(@"   server = %@", challenge.protectionSpace.host);
        completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
    } else if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodNTLM]) {
        NSLog(@"   NSURLAuthenticationMethodNTLM");
        NSURLCredential *credential = [NSURLCredential credentialWithUser:@"username" password:@"passwordIsSecretShhh" persistence:NSURLCredentialPersistenceForSession];
        completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
    } else {
        NSLog(@"   ????");
    }
}

即使它完全失败并且无法加载,我仍然可以跳到 Safari,输入 URL 并加载它。因此,我正在寻找会导致此问题的想法,而不是网络问题或托管 Web 服务器的参差不齐的问题。

【问题讨论】:

  • 你有解决这个握手错误的方法吗?
  • 不。不是一回事。我注意到有时它会重试并正常工作,但有时会连续失败 3 次并导致完全连接失败。

标签: ios ssl nsurlsessiondownloadtask


【解决方案1】:

我终于解决了这个问题。它与我的代码无关。

问题是由安装在服务器中的 Trend SSL 监控软件引起的。一旦软件被禁用,错误就会立即消失。

这不是一个很好的答案,但希望它能对其他人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-08
    • 2015-07-29
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多