Search code examples
phppostnginxmultipart

$_POST is empty even though CONTENT_LENGTH is correct


I've got an HTTP POST pointed at two different places.

The first location is handled by a thirdparty solution, so I can't see how they're handling the data (which they must be because the values are getting through and I'm seeing results).

In my location, I have an NGINX server (which has never had any problems before with lots of use). I am using php to read the POST data, and I expect the content to be in the $_POST variable as the POST is $_SERVER["CONTENT_TYPE"] => "multipart/form-data"

But, even though the type and the $_SERVER["CONTENT_LENGTH"] are correct, I'm getting nothing in my $_POST, $_REQUEST, and when checking file_get_contents('php://input') there is nothing inside either.

The body is a very small json lump (<1k). Always an array of objects.

To see what's in the arrays I used echo json_encode( array( "GET" => $_GET, "POST" => $_POST, "REQUEST" => $_REQUEST, "SERVER" => $_SERVER ) )

I've run out of ideas of what to check now.

the entry $_SERVER["PHP_SELF"] has a strange garbling possibly due to the path delimiters?


Solution

  • How to post JSON to PHP with curl lead me to the solution:

    Don’t forget to send it as application/json

    Once I did that, the data came through in the body. This helps me, but I'm still curious as to why the third party receiver can handle the data as it was.