400 BAD 请求 HTTP 错误代码含义? [英] 400 BAD request HTTP error code meaning?
问题描述
我有一个 JSON 请求,我将其发布到 HTTP URL.
I have a JSON request which I'm posting to a HTTP URL.
这是否应该被视为 400
,其中 requestedResource
字段存在但 "Roman"
是该字段的无效值?
Should this be treated as 400
where requestedResource
field exists but "Roman"
is an invalid value for this field?
[{requestedResource:"Roman"}]
这是否应该被视为 400
其中 "blah"
字段根本不存在?
Should this be treated as 400
where "blah"
field doesn't exist at all?
[{blah:"Roman"}]
推荐答案
A 400 表示请求格式错误.也就是说,客户端向服务器发送的数据流没有遵循规则.
A 400 means that the request was malformed. In other words, the data stream sent by the client to the server didn't follow the rules.
对于具有 JSON 有效负载的 REST API,400 通常用于指示 JSON 以某种方式根据服务的 API 规范无效,而且我会正确地说.
In the case of a REST API with a JSON payload, 400's are typically, and correctly I would say, used to indicate that the JSON is invalid in some way according to the API specification for the service.
按照这个逻辑,您提供的两个场景都应该是 400 秒.
By that logic, both the scenarios you provided should be 400s.
想象一下,这是 XML 而不是 JSON.在这两种情况下,XML 永远不会通过模式验证——因为未定义的元素或不正确的元素值.那将是一个糟糕的要求.同样的交易在这里.
Imagine instead this were XML rather than JSON. In both cases, the XML would never pass schema validation--either because of an undefined element or an improper element value. That would be a bad request. Same deal here.
这篇关于400 BAD 请求 HTTP 错误代码含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!