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

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

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

9条回答
  •  醉梦人生
    2020-11-28 01:32

    The WCF API in .NET handles missing parameters by returning an HTTP 404 "Endpoint Not Found" error, when using the webHttpBinding.

    The 404 Not Found can make sense if you consider your web service method name together with its parameter signature. That is, if you expose a web service method LoginUser(string, string) and you request LoginUser(string), the latter is not found.

    Basically this would mean that the web service method you are calling, together with the parameter signature you specified, cannot be found.

    10.4.5 404 Not Found

    The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.

    The 400 Bad Request, as Gert suggested, remains a valid response code, but I think it is normally used to indicate lower-level problems. It could easily be interpreted as a malformed HTTP request, maybe missing or invalid HTTP headers, or similar.

    10.4.1 400 Bad Request

    The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

提交回复
热议问题