php - 如何在 PHP 中获取发送的 json POST cURL
问题描述
我正在尝试使用 post 访问从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'));
?>
解决方案
推荐阅读
- php - PHP - 多维数组中食物的所有子类别
- asp.net-core - EntityFrameworkCore 插入现有的相关项
- python - Pytorch 通过两个大小为 [n,n] 的张量来索引 [n*n*3] 的张量
- ios - 使用 API 的 UICollectionView 分页
- r - 将一个csv文件分成四个不同的文件
- python - 如何使用 Pandas read_csv?
- c# - 构建动态过滤器表达式
- azure-sql-database - 互联网中断时如何访问我的 Azure Sql 数据库?
- php - PHP escape_string 返回 0。注册系统
- deep-learning - DNN - 使用灰度图像而不是 RGB 进行训练是个好主意吗