I’m using curl to send this:
curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d "{firstname:james}" http://hostname/index.php
I’m trying to display POST like this in index.php
<?php
die(var_dump($_POST));
?>
Which outputs
array(0) {
}
I must be misunderstanding something about sending JSON data via POST
Thank you for your time
$_POSTis an array that is only populated if you send the POST body in URL encoded format. PHP does not parse JSON by itself automatically and hence does not populate the$_POSTarray. You need to get the raw POST body and decode the JSON yourself: