400 BAD request HTTP error code meaning?

前端 未结 8 1210
迷失自我
迷失自我 2020-11-22 03:38

I have a JSON request which I\'m posting to a HTTP URL.

Should this be treated as 400 where requestedResource field exists but \"Rom

8条回答
  •  情话喂你
    2020-11-22 04:09

    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.

    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.

    By that logic, both the scenarios you provided should be 400s.

    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.

提交回复
热议问题