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

获取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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作