gpt4 book ai didi

iOS/Obj-c - 获取 HTTP 状态代码响应消息(原因短语)

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:09:23 25 4
gpt4 key购买 nike

我正在使用一个 API,它针对许多不同的错误发回 HTTP 406,以及一条自定义消息(原因短语)。它可能看起来像:

406 Not Acceptable:用户已经登录406 Not Acceptable :缺少密码字段406 Not Acceptable:节点不存在。

我可以使用以下方法获取 406 状态代码和标准的“ Not Acceptable ”字符串:

NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;

NSInteger statusCode = [HTTPResponse statusCode];

[NSHTTPURLResponse localizedStringForStatusCode:HTTPResponse.statusCode];

但是我真的需要原因短语消息来知道如何处理响应。我怎样才能得到它,最好使用标准的 iOS SDK?

最佳答案

I really require the reason phrase message to know how to handle the response.

然后 API 就坏了。原因短语仅用于调试辅助。这并不意味着告知客户行为。

来自 RFC 2616 § 6.1.1 :

The Status-Code is intended for use by automata and the Reason-Phrase is intended for the human user. The client is not required to examine or display the Reason- Phrase.

如果有关于响应的信息无法单独通过状态代码传达,则适当的位置是作为标题或在响应主体中。原因短语不是放置客户使用所需信息的正确位置。

关于iOS/Obj-c - 获取 HTTP 状态代码响应消息(原因短语),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21859791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com