【网络123】Http返回码

背景:遇到一个http访问相关bug,调试code后发现开发人员针对http返回code进行判断成功与否时,仅仅预定义了一个200返回码。但实际返回201,故导致判断逻辑错误。

参考:https://developer.mozilla.org/en-US/docs/Web/HTTP/Status

了解一下常见的http返回码分类:

HTTP状态码:总共分为5种类型

         1字开头:代表消息类型

         2字开头:代表成功类型

         3字开头:代表重定项类型

         4字开头:代表错误类型

         5字开头:代表服务器错误

200 OKThe request has succeeded. The meaning of the success depends on the HTTP method:

  • GET: The resource has been fetched and is transmitted in the message body.
  • HEAD: The entity headers are in the message body.
  • PUT or POST: The resource describing the result of the action is transmitted in the message body.
  • TRACE: The message body contains the request message as received by the server

201 CreatedThe request has succeeded and a new resource has been created as a result. This is typically the response sent after POST requests, or some PUT requests.

原文地址:https://www.cnblogs.com/cathygx/p/13559170.html