如何在PHP中获取发送的JSON POST cURL

时间:2019-05-12 13:05:14

标签: php json curl post get

我正在尝试使用帖子访问从 sender.php 发送到 receiver.php 的数据。

这是我的 sender.php

<?php
 $param = array(
        'Name' => 'Mark',
        'Age' => '28'
    );
    $ch = curl_init();

    curl_setopt_array($ch, array(
        CURLOPT_URL => 'https://example/receiver.php',
        CURLOPT_POST => 'TRUE',
        CURLOPT_HEADER => TRUE,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_HTTPHEADER => array(
            'Content-Type: application/json',
            'Content-Length: '.strlen(json_encode($param))
        ),
        CURLOPT_POSTFIELDS => json_encode($param),
        )
    );

$result = curl_exec($ch);
curl_close($ch);
print_r($result);


?>

这是我的 receiver.php 。 我需要如何显示输入的数据的帮助

<?php
echo json_decode(file_get_contents('https://example/sender.php'));
?>

0 个答案:

没有答案