What HTTP status response code should I use if the request is missing a required parameter?

后端 未结 9 1910
心在旅途
心在旅途 2020-11-28 01:15

I am thinking 412 (Precondition Failed) but there may be a better standard?

相关标签:
9条回答
  • 2020-11-28 01:38

    I often use a 403 Forbidden error. The reasoning is that the request was understood, but I'm not going to do as asked (because things are wrong). The response entity explains what is wrong, so if the response is an HTML page, the error messages are in the page. If it's a JSON or XML response, the error information is in there.

    From rfc2616:

    10.4.4 403 Forbidden

    The server understood the request, but is refusing to fulfill it.
    Authorization will not help and the request SHOULD NOT be repeated.
    If the request method was not HEAD and the server wishes to make
    public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404
    (Not Found) can be used instead.

    0 讨论(0)
  • 2020-11-28 01:43

    I'm not sure there's a set standard, but I would have used 400 Bad Request, which the latest HTTP spec (from 2014) documents as follows:

    6.5.1. 400 Bad Request

    The 400 (Bad Request) status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

    0 讨论(0)
  • 2020-11-28 01:43

    It could be argued that a 404 Not Found should be used since the resource specified could not be found.

    0 讨论(0)
提交回复
热议问题