0

POST or PUT method need content-length in request header field.

Does another method(GET, PATCH, DELETE, OPTIONS, CONNECT, TRACE, HEADER) also need content-length?

About content-length in Response, specification is described in rfc2616.

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

Althought, I couldn't find specification about request header..

tamagohan2
  • 445
  • 4
  • 15

1 Answers1

1

The HTTP specification has been updated from RFC2616. Refer to the following instead:

  • RFC7230 - HTTP/1.1: Message Syntax and Routing
  • RFC7231 - HTTP/1.1: Semantics and Content
  • RFC7232 - HTTP/1.1: Conditional Requests
  • RFC7233 - HTTP/1.1: Range Requests
  • RFC7234 - HTTP/1.1: Caching
  • RFC7235 - HTTP/1.1: Authentication

Specifically Section 3.3.2 of RFC7230

A Content-Length SHOULD be sent WHEN the request includes a payload body and a Transfer-Encoding header is not set.

So even a POST or PUT only need to send a Content-Length when there is a body to have a length, this just happens normally be the case with a POST and PUT due to the operations.

There is no problem with sending a Content-Length of 0 to indicate no body, but that is implied by not having a Content-Length or Transfer-Encoding.

These are just the specs though, so your mileage may vary with different http implementations.

Community
  • 1
  • 1
Matt
  • 68,711
  • 7
  • 155
  • 158