According to the PHP manual, $_POST
works with application/x-www-form-urlencoded
and multipart/form-data
content types. You are sending JSON (application/json
). Since $_POST
is an associative array created from posted form data, and you are not posting a form, it's not surprising that it would be empty.
To get the raw JSON from the request body you need to use php://input
$json = file_get_contents('php://input');
To deserialize the JSON to an object you can use json_decode
.
$logPostData = json_decode($json);
If you want the data to be converted into an associative array like $_POST
, you can pass true
as the second parameter:
$logPostData = json_decode($json, true);