400 BAD request HTTP error code meaning?

前端 未结 8 1156
迷失自我
迷失自我 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:10

    Using 400 status codes for any other purpose than indicating that the request is malformed is just plain wrong.

    If the request payload contains a byte-sequence that could not be parsed as application/json (if the server expects that dataformat), the appropriate status code is 415:

    The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.

    If the request payload is syntactically correct but semantically incorrect, the non-standard 422 response code may be used, or the standard 403 status code:

    The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated.

    0 讨论(0)
  • 2020-11-22 04:14

    Think about expectations.

    As a client app, you expect to know if something goes wrong on the server side. If the server needs to throw an error when blah is missing or the requestedResource value is incorrect than a 400 error would be appropriate.

    0 讨论(0)
提交回复
热议问题