400 BAD请求HTTP错误代码含义? [英] 400 BAD request HTTP error code meaning?

查看:189
本文介绍了400 BAD请求HTTP错误代码含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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是通常,我会说,根据服务的API规范,用于表示JSON在某种程度上无效。

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 400's.

想象一下,这是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屋!

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