应在我的应用程序中检查哪些 HTTP 状态代码
我只是想知道如果出现故障并且我在标准 202 之外的其他内容中返回,则应该检查 HTTP 状态代码,有很多状态代码,但我想知道大多数情况下应该检查哪些状态代码,
我使用的是 android,但这在整个网络中都是相似的,所以如果有人能够告诉他们测试了哪些以及向用户显示了哪些消息,那就太好了。
我如何找到 android 中响应的状态代码?
i am just wondering about the HTTP status codes that should be checked against if something fails and i am returned within something other than the standard 202, there are alot of status codes but i am wondering what ones should be checked for the majority of the time,
i am using android but this is similar through the whole web, so it would nice if someone could tell which ones they test for and what messages they show to users.
and how would i find out the status code of a response in android?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
作为一个通用的东西,我倾向于只检查 100 的数字。 2=好的,3=再试一次/看这里,4=你犯了一个错误,5(或其他)=他们犯了一个错误。通常,这些信息足以让我提供合理的反馈...
尽管大多数 HTTP 库都会为我处理 3xx 消息(如果我要求的话),所以在应用程序级别,主要关注的是 4xx 与 5xx 消息。
除非您有特定原因要检查更具体的代码,否则 4xx 可能意味着您发送的任何请求由于某种原因都是无效的 - 所以我可能想要求用户提供新的输入,或类似的东西;但 5xx 通常意味着服务器“损坏”,我需要告诉用户“服务目前不可用”或类似信息。我个人经常将 DNS 和 TCP 连接错误集中到与 5xx 错误相同的处理程序中……作为服务器的“客户端”用户,通常对我来说服务不可用的原因并不那么重要,仅是否是。
As a general-purpose thing, I tend to just check the 100's digit. 2=OK, 3=try again/look over here, 4=you made a mistake, 5 (or anything else)=they made a mistake. Usually, that's enough information for me to give reasonable feedback...
Although most HTTP libraries will handle the 3xx messages for me, if I ask them to, so at the application level, it's mostly a concern with 4xx versus 5xx messages.
Unless you have a specific reason to check for more specific codes, 4xx probably means that whatever request you sent was invalid for some reason — so I may want to ask the user for new input, or something like that; but 5xx generally means the server is "broken" and I need to tell the user that the "service is presently unavailable" or similar. I personally often funnel DNS and TCP connection errors into the same handler as 5xx errors… as a "client" side user of the server, it doesn't usually matter to me so much why the service is unavailable, only whether it is.
取决于您的服务器预计发送的内容。
Depends on what your servers is expected to send.
我会考虑处理这些:303、400、401、404、500、503。
I'd look at handling these: 303, 400, 401, 404, 500, 503.