0

i need to write a full http request packet with POST method. POST require Content-Length field to be accepted, but i don't know packet size until i've write it all. Can i add Content-Length field at the end of http request? and Content-Length field size need to be included in length count?

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
giozh
  • 9,868
  • 30
  • 102
  • 183

3 Answers3

1

Maybe I am not fully understanding your question but why do you need to put packet size in the Content-Length field? Content-Length contains the size of the message body (post contents) and not the packet size.

According to the specs:

The Content-Length entity-header field indicates the size of the entity-body

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
0

No, header fields come first. You'll either need to buffer, or use Transfer-Encoding: chunked (in which case you don't need Content-Length).

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
0

You needn't specify content-length if you don't know exact size of your response.

Also it depends on HTTP version that you use.

For v1.0 you can send data until you reach the end of your stream, then you can simply close the connection and this is normal behavior for HTTP 1.0.

Khachatur
  • 921
  • 1
  • 12
  • 30