简单问题:
我有一个 POST 端点,它需要一些文本输入。输入的文本不得超过 x 个字符。如果是,我会回复一条错误消息。
但是哪个 HTTP 状态码才是正确的呢?
0.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. [..]
10.4.7 406 Not Acceptable
The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.
10.4.18 417 Expectation Failed
The expectation given in an Expect request-header field [..] could not be met by this server [..]
最佳答案
我猜这是存在的问题。 很快,正确的 HTTP 代码是 400 + 可选描述。
您可以在此处查看更详细的答案:REST HTTP status codes for failed validation or invalid duplicate
关于违反发布要求的 HTTP 403 或 406?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34327947/