dongmoxin7111 2017-05-20 00:21
浏览 514

获取CURL RAW在PHP中发布JSON数据

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题