如果缺少必需的标头,返回的最合适的HTTP状态代码是什么? [英] What is the most appropriate HTTP status code to return if a required header is missing?

查看:335
本文介绍了如果缺少必需的标头,返回的最合适的HTTP状态代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了但它并没有特别询问标题,似乎没有达成共识。

I read What HTTP status response code should I use if the request is missing a required parameter? but it did not specifically ask about headers and there didn't seem to be a consensus.

此问题的上下文假定验证成功。我目前偏爱400(虽然感觉不对,因为这不是格式错误的语法)或403.鉴于403的描述:

The context of this question assumes successful authentication. I'm currently favoring either a 400 (though that doesn't feel right because this isn't really a case of "malformed syntax") or 403. Given 403's description:

服务器理解请求,但拒绝履行请求。
授权无效,请求不应重复。 如果
请求方法不是HEAD且服务器希望公开
,为什么请求尚未完成,它应该描述实体拒绝的原因
。 / strong>

The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity.

这对我来说最有意义。

可以有人请赐教?谢谢。

Can someone please enlighten me? Thanks.

推荐答案

400错误请求

这是一个用户错误请求。与403不同,客户允许重复他们的请求,但仅在修改后:

It's a user error in the request. Unlike with a 403, the client should be allowed to repeat their request, but only after modification:


10.4.1 400错误请求 由于语法格式错误,服务器无法理解该请求。客户不应在未经修改的情况下重复请求。

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.

编辑

Edit

正如Mark Reed在评论中指出的那样,403说:你发给我的东西没有任何问题。你有适当的授权,语法是有效的。我只是穿上我想做你问的事。

As Mark Reed points out in the comments, a 403 says, "There is nothing wrong with what you sent me. You have proper authorization and the syntax was valid. I just don't want to do what you ask."

你粗体的部分简单地说,如果服务器如此选择,它可以告诉客户端确切的原因我想完成请求。

The part that you have in bold simply says, if the server so chooses, it can tell the client exactly why it doesn't want to fulfill the request.

这篇关于如果缺少必需的标头,返回的最合适的HTTP状态代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆