我通过cURL从服务器发送原始数据,其中数据类型为JSON,如
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"}'
现在我想读取发布到我的listener.php文件的数据,并将JSON数据解码为PHP数组,最后将其插入我们的MySQL数据库。
以下是https://website-to-post-data.com/listener.php文件
的代码<?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);
?>
为什么我在执行上述代码时没有收到空白输出而没有收到数据?