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

后端 未结 9 1975
心在旅途
心在旅途 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.

提交回复
热议问题