如何捕获发布到PHP脚本的任何内容,即使它格式不正确?

For example, properly formatted would look something like this (I just did a var_dump on incoming POST request):

array(1) { ["fred"]=> string(6) "barney" }

But what if I sent badly formatted/mangled data, like the naked string "test"?

This is what I'm trying to capture. I'm sending it with the postman chrome extension. My script dumps all of POST into a log file, but since it's just the word "test", it doesn't show up. How would I capture this and all other cases of data sent to my script?

You can use the php://input stream to get the data you want.

http://us.php.net/manual/en/wrappers.php.php

This is the prefered method instead of using $HTTP_RAW_POST_DATA, because:

it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".

Example: var_dump(file_get_contents('php://input'));