违反发布要求的 HTTP 403 或 406?

标签 http http-status-codes

简单问题:

我有一个 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 [..]

Source: w3.org

最佳答案

我猜这是存在的问题。 很快,正确的 HTTP 代码是 400 + 可选描述

您可以在此处查看更详细的答案:REST HTTP status codes for failed validation or invalid duplicate

关于违反发布要求的 HTTP 403 或 406?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34327947/

相关文章:

WCF 4 REST 服务无法返回 StatusDescription,仅返回 StatusCode

javascript - RESTful ajax - "item not found"的 HTTP 状态代码是什么?

ajax - Angular JS 成功了,但后来不行了,为什么?

silverlight - silverlight 中每个 URL 的不同配置

ruby-on-rails - Rails 3.2 `link_to`(在电子邮件中) `method: :put` 仍在生成 GET 请求

http - 200 HTTP 代码在非 url 字符串

java - 带有需要枚举参数的注释的 clojure gen-class

javascript - 错误 : request entity too large

django - 使用@require_POST 时如何在 Django 中显示 HTTP 状态 405(不允许的方法)的自定义错误页面

rest - 外部依赖错误的 HTTP 状态码