Is an HTTP PUT request required to include a body?

后端 未结 5 465
失恋的感觉
失恋的感觉 2020-12-07 20:03

I\'m having trouble finding a definite specification of this in the standard. I have an HTTP client that\'s not including a Content-Length: 0 header when doing

5条回答
  •  孤街浪徒
    2020-12-07 20:30

    HTTP requests have a body if they have a Content-Length or Transfer-Encoding header (RFC 2616 4.3). If the request has neither, it has no body, and your server should treat it as such.

    That said it is unusual for a PUT request to have no body, and so if I were designing a client that really wanted to send an empty body, I'd pass Content-Length: 0. Indeed, depending on one's reading of the POST and PUT method definitions (RFC 2616 9.5, 9.6) one might argue that the body is implied to be required - but a reasonable way to handle no body would be to assume a zero-length body.

提交回复
热议问题