对于仅 AJAX URL 的非 AJAX 请求,我应该返回什么状态代码?
如果不使用 AJAX 请求 URL,应返回什么状态代码? 400?
If the URL is requested not using AJAX what status code should be returned? 400?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为
403 Forbidden
是最好的。501 Not Implemented
不太适合,因为资源已实现,但不适合这种请求。400 Bad Request
也不是一个好的选择,因为根据规范,这意味着“由于语法错误,服务器无法理解该请求”,但这里的情况并非如此。I think
403 Forbidden
ist best.501 Not Implemented
does not fit well, because the resource is implemented, but just not suited for that kind of request.400 Bad Request
ist not a good choice either, because this implies, according to the spec, that "the request could not be understood by the server due to malformed syntax", which is not the case here.我不相信你通过监管这个价值观真的能帮助任何人。我更喜欢在所有情况下都尝试发回有用数据的理念。然而,不难想象我们确实需要一项政策的类似情况。例如,假设我们有一个可以根据 mime 类型返回 JSON 或 XML 的服务,如果指定了意外的 mime 类型,也许最好返回一个清晰的响应代码。
W3 说
因此,很明显,响应应该是 4xx,而不是客户端提供无效请求。我会选择 400 BAD REQUEST 并确保返回的文本解释了为什么请求被认为是错误的。
W3 对于 400 表示:请求语法错误或本质上不可能得到满足,情况似乎确实如此。
I'm not convinced that you're really helping anyone by policing this value. I'd prefer a philosophy of trying to send back useful data in all cases. However, it's not much of a stretch to imagine similar situations where we do need a policy. For example, suppose we have a service that can return JSON or XML depending upon the mime type, perhaps it is better to return a clear response code if an unexpected mime type is specified.
W3 say
And so it seems clear that the response should be a 4xx, it't the client supplying an invalid request. I'd go with 400 BAD REQUEST and make sure that the text returned explains why the request is considered bad.
W3 says for 400: The request had bad syntax or was inherently impossible to be satisfied, and that does indeed seem to be the case.
我会选择
400 Bad Request
,因为它意味着不重试请求。如果做不到这一点,
418 我是一个茶壶
,只是为了迷惑他们:)I'd go
400 Bad Request
, since it has the implication not to retry the request.Failing that,
418 I'm a teapot
, just to confuse 'em :)