如何在 PHP 中获取原始请求?

问题描述 投票:0回答:2

我的服务器上有一个名为 api.php 的脚本。我使用 POST 请求从其他服务器调用它。有什么方法可以获取 POST 请求的 api.php 原始内容吗?

php api post request
2个回答
12
投票

使用以下代码

$data = file_get_contents('php://input');

0
投票

@艾哈迈德·阿曼
我认为使用错误控制运算符会更好,因为请求 API 的人可能不会在他的请求中发送正文。

$payload = @file_get_contents('php://input');
$data = json_decode($payload);
© www.soinside.com 2019 - 2024. All rights reserved.