Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 URI,可以通过 POST 获得。 它需要4 个 POST 参数。
如果用户没有向我传递所有必需的参数,我应该使用什么 HTTP 响应状态代码?
406?
你最好使用 400 而不是 406:
406 Not Acceptable 请求的资源只能生成根据请求中发送的 Accept 标头不可接受的内容。 [2 400 Bad Request 由于语法错误,请求无法完成。[2]
406 Not Acceptable 请求的资源只能生成根据请求中发送的 Accept 标头不可接受的内容。 [2
400 Bad Request 由于语法错误,请求无法完成。[2]
HTTP 状态码列表
此外,您可以生成一个Exception更好的,因为您可以编写一个自定义错误来指示请求有什么问题。
Exception