I am getting raw data sent from server through cURL where data type is JSON, like
curl -X POST https://website-to-post-data.com/listener.php -H 'content-type: application/json' -d '{"user_id": "1234", "Date": "2017-04-06", "first_name": "First Name", "last_name": "Last Name", "email": "someemail@email.com"}'
Now I want to read this data posted to my listener.php file and decode the JSON data to PHP array and finally insert it in our MySQL database.
Here is the code of https://website-to-post-data.com/listener.php file
<?php
$json_string = file_get_contents('php://input');
$ch = curl_init( 'https://website-to-post-data.com/listener.php' );
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Accept: application/json;charset=utf-8',
'Content-Type: application/json;charset=utf-8',
'Expect: 100-continue',
'Connection: Keep-Alive') ,
CURLOPT_POSTFIELDS => $json_string
);
curl_setopt_array( $ch, $options );
$result = curl_exec($ch); // Getting jSON result string
echo $result;
$jsArray = json_decode($result);
?>
Why I am getting blank output on executing the above code and not receiving the data?