【问题标题】:What are all the NSURLErrorDomain errors with equivalent HTTP status codes?具有等效 HTTP 状态代码的所有 NSURLErrorDomain 错误是什么?
【发布时间】:2016-03-10 20:50:18
【问题描述】:

NSURLErrorDomain errors 的文档中,NSURLErrorBadServerResponse 的描述被列为:

当 URL 加载系统从 服务器。

这相当于HTTP发送的“500 Server Error”消息 服务器。

是否存在其他具有等效 HTTP 状态代码的 NSURLErrorDomain 错误?例如,NSURLErrorTimedOut 是否等同于 408 Request Timeout?

【问题讨论】:

    标签: ios cocoa http-status-codes foundation nserror


    【解决方案1】:

    这些值在 NSURLError.h 中定义。如果您在 Mac 上的 Spotlight 搜索中键入 NSURLErrorDomain,它会在某处找到相应的文件,在我的情况下是在 /Library/Developer/../SDKs/.. 中。

    更新了 Apple 开发者网站上 URL 加载系统错误代码的 URL:https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes?language=occ

    【讨论】:

      【解决方案2】:

      (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/)

      要获得 http 状态码,将返回的 NSURLResponse 转换为 NSHTTPURLResponsestatusCode 属性将拥有它。

      例如:

      let httpResponse = response as? NSHTTPURLResponse
      let statusCode = httpResponse.statusCode
      

      对于 Apple 的文档,请转到 Foundation Constants Reference 并在右上角的搜索字段中输入错误名称。您也可以选择语言,在选项下,您可以选择“部署目标”和“自动扩展所有符号”,选中“自动扩展所有符号”。

      对于NSURLErrorBadServerResponse,单击“在此页面上”并输入 NSURLErrorBadServerResponse。然后单击搜索字段下黄色突出显示的名称。 您将进入以下部分:这些值作为域“NSURLErrorDomain”的 NSError 对象的错误代码属性返回。
      向下滚动(使用 Safari 搜索)到 NSURLErrorBadServerResponse

      NSURLErrorBadServerResponse 当 URL 加载系统从服务器接收到错误数据时返回。 这相当于 HTTP 服务器发送的“500 Server Error”消息。 在 OS X v10.2 及更高版本中可用。

      其他可能有用的错误站点:

      HTTP status codes
      Status Code Definitions

      【讨论】:

      • 我正在寻找与状态代码而非代码匹配的错误代码列表。
      • 我可以找到 HTTP 状态代码。我找不到与 NSURLErrorDomain 错误匹配的状态代码列表。
      • 用苹果的“Foundation Constants Reference”信息更新了答案
      猜你喜欢
      • 2013-11-20
      • 2010-09-21
      • 2020-07-06
      • 2016-09-14
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多