【问题标题】:Getting NSURL Error -1012 in NSURL Request在 NSURL 请求中获取 NSURL 错误 -1012
【发布时间】:2015-09-24 13:18:55
【问题描述】:

我正在创建使用 HTTPS 上托管的 rest API 的 iOS 应用程序。此域具有 有效的 CA 批准证书,适用于 SSLTLS。但是,当我从我的应用程序发出 NSURL 请求时,它第一次运行良好,但半小时后,当我发出 NSURL 请求时,它返回 NSURL 错误 -1012

我还尝试使用以下提到的方法处理 身份验证挑战TLS 链验证- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

我使用的过程在下面的链接中提到: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html#//apple_ref/doc/uid/TP40009507-SW3

当我调试 canAuthenticateAgainstProtectionSpace 并检查 protectionspace 值时,它显示的请求存在 NSURLAuthenticationMethodServerTrust 问题。

我尝试了不同的不同方案来处理这个问题。 1. 在 canAuthenticateAgainstProtectionSpace 方法中,如果我发现 NSURLAuthenticationMethodServerTrust 验证然后我返回 NO,然后 didReceiveAuthenticationChallenge 方法从未调用但 API 返回空白字符串。 2. 在 canAuthenticateAgainstProtectionSpace 方法中,如果我发现 NSURLAuthenticationMethodServerTrust 验证然后我返回 YES,然后调用 didReceiveAuthenticationChallenge 方法并且当我使用 continueWithoutCredentialForAuthenticationChallenge strong>,performDefaultHandlingForAuthenticationChallenge 和 cancelAuthenticationChallenge 方法一一但什么也没发生我得到相同的结果空白字符串,并且在 cancelAuthenticationChallenge 我得到 NSURL 错误 -1012

我们的 API 托管在 http://uat-exchange.vrmco.com/

请帮我解决我所缺少的或者我们需要用来解决此错误的任何东西。

提前致谢。

【问题讨论】:

    标签: nsurlconnection nsurl nsurlconnectiondelegate


    【解决方案1】:

    如果它第一次工作,我认为这不是 TLS 问题。 IIRC,除非您提供自定义 TLS 处理程序方法(在您的 canAuthenticateAgainst... 方法中为服务器信任保护空间返回 YES),否则 1012 错误通常意味着无法将 user 身份验证到 server 而不是相反。 (TLS 失败还有其他错误代码,尤其是 1202。)

    我的第一个猜测是您的服务器需要某种基于 cookie 的身份验证,并且在该 cookie 过期时返回 HTTP 401 错误代码。如果是这样,您可能应该将其视为您需要重做登录过程的指示。

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-20
      • 2015-04-06
      相关资源
      最近更新 更多