Search code examples
phphttppostnetwork-programmingresponse

Is it possible that HTTP Response adds content?


HTTP/1.1 200 OK\r\n
Date: Tue, 29 Jun 2021 10:48:59 GMT\r\n
Server: Apache\r\n
Upgrade: h2\r\n
Connection: Upgrade, close\r\n
Vary: Accept-Encoding\r\n
Transfer-Encoding: chunked\r\n
Content-Type: text/html; charset=UTF-8\r\n
\r\n
3\r\nEND\r\n0\r\n\r\n

What I am sending in PHP is only <?php die('END'); ?>

Where does this '3' come from? And where does this zero come from, in the response?

Request:

POST / HTTP/1.1\r\n
Host: " . $host . "\r\n
Content-type: application/x-www-form-urlencoded\r\n
Content-length: ".strlen($str)."\r\n
Connection: Close\r\n\r\n
str=string

Solution

  • The numbers represent the length of the chunks of the chunked HTTP output.

    See https://en.wikipedia.org/wiki/Chunked_transfer_encoding#Example

    If you'd like to turn it off, see this SO post.