How to get request body without content-length?

Is there any way to retrieve a request body when a content-length header is not included in the request?

for example, I have this in /var/www/test.php:

print_r(apache_request_headers());
$data = file_get_contents('php://input');
var_dump($data);

And run this command:

curl -X POST -d test --header 'Content-Length: ' localhost/test.php

I see that there is no content-length header, and $data is empty. If I specify, for instance, a content-length of '3', I get an output for $data of 'tes'.

Is there any way to make php retrieve the request body, irrespective of the content-length header?

Answers


Is there any way to retrieve a request body when a content-length header is not included in the request?

Yes. But you are including it in the request.

curl -d test localhost/test.php should return:

Array
(
    [User-Agent] => curl/7.xx.x
    [Host] => localhost
    [Accept] => */*
    [Content-Length] => 4
    [Content-Type] => application/x-www-form-urlencoded
)

string(4) "test"

You can just omit sending the header.


Need Your Help

How to add localhost to php regex?

php regex

I don't know how to compose regex but I need to make localhost url valid in one of the program I'm using. This is the regex the program uses to validate URL:

Why do .NET winforms scale improperly at large DPI settings?

.net winforms

My .NET application (VB.NET 3.5 if you really must know) forms do not properly format when rendered at high DPI settings. All of the fixes I've found so far simply explain the cause of the problem...