HTTP Status code for malformed POST body

2019-04-04 10:58发布

问题:

What status code should a REST service return in response to a POST request containing a malformed / unparseable message body?

回答1:

400 Bad Request

Straight from the specification:

The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.

Alternatively, if you need a more specific status you can create your own 4XX status for whatever API you might be designing.



回答2:

400 - Bad Request

From Hypertext Transfer Protocol -- HTTP/1.1 (RFC-2616):

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.



回答3:

I'd say 412 Precondition Failed



标签: rest post