HTTP 状态代码是否在 iOS SDK 中的任何位置定义?
有谁知道 HTTP 状态代码是否/在哪里,如此处指定, iOS SDK 中有定义吗?或者我应该在常量文件中手动重新定义它们?
Does anyone know if/where the HTTP status codes, as specified here, are defined in the iOS SDK? Or should I expect to manually re-define them in a constants file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
好吧,它们的定义是
可以返回给定状态代码的字符串。这就是您要找的吗?
Well, they are defined in the sense that
can return a string for the given status code. Is that what you are looking for?
我进去了
,
却两手空空,所以答案几乎肯定是“不”。
I did a
in
and came up empty handed so the answer is almost certainly "no".
有一个完整的 Obj-C 库,其中包含迄今为止定义的所有代码:
https://github.com/rafiki270/HTTP-Status-Codes- for-Objective-C
更新:
新的 Swift 版本在这里:
https://github.com/manGoweb/StatusCodes
There is a complete Obj-C library with all the codes defined to date:
https://github.com/rafiki270/HTTP-Status-Codes-for-Objective-C
UPDATE:
New Swift version is here:
https://github.com/manGoweb/StatusCodes
恐怕您必须手动定义它们。我不熟悉 Objective-C,以下是我的快速定义:
HTTP Status Enum in Swift 4 based on https:// /httpstatuses.com/
HttpStatusEnum.strings
:I'm afraid you'll have to manually define them. I'm not familiar with Objective-C, following is my swift definition:
HTTP Status Enum in Swift 4 based on https://httpstatuses.com/
HttpStatusEnum.strings
:http状态码可以由服务器响应来定义。当有连接时,可以使用 NSURLResponse 来读出 statusCode。
这些 4** 响应可以在您的服务器内部定义。
The http status code can be defined by the server response. When there is a connection, you can use the NSURLResponse to read out the statusCode.
Those 4** response can be defined internally on your server.
我也找不到我期望存在的头文件,所以我不得不编写自己的一个。
HTTPStatusCodes.h 包含在 GitHub 上的 nv-ios-http-status 项目中,基于 HTTP 状态码的调度可以如下编写。
我希望 HTTPStatusCodes.h 可以节省您和其他开发人员的时间。
I also could not find a header file which I expected to exist, so I had to write one of my own.
With HTTPStatusCodes.h contained in nv-ios-http-status project at GitHub, dispatch based on HTTP status codes can be written like the following.
I hope HTTPStatusCodes.h can save time of you and other developers.
还有一个 Swift 挂件可以重用它:
https://github.com/rhodgkins/SwiftHTTPStatusCodes
There is also a Swift pendant to reuse it:
https://github.com/rhodgkins/SwiftHTTPStatusCodes