【发布时间】:2013-05-29 19:30:37
【问题描述】:
我正在尝试使用 PHP 捕获 curl 发送的数据,但它没有出现在我的端。
我正在通过控制台执行:
curl -d "tests_123" "http://www.example.com/capture.php"
我在 capture.php 中有
print_r($_POST);
print_r($_GET);
print_r($_REQUEST);
但什么也没有出现。
我做错了吗?
【问题讨论】:
我正在尝试使用 PHP 捕获 curl 发送的数据,但它没有出现在我的端。
我正在通过控制台执行:
curl -d "tests_123" "http://www.example.com/capture.php"
我在 capture.php 中有
print_r($_POST);
print_r($_GET);
print_r($_REQUEST);
但什么也没有出现。
我做错了吗?
【问题讨论】:
我确定你可以通过$response = file_get_contents('php://input');获取数据
但是,如果您稍微更改一下命令,并为您发送的值添加一个键,您可以很容易地从您的 $_POST 变量中获取数据。
curl -d "Mykey=tests_123" "http://www.example.com/capture.php"
print_r($_POST);
// array ( Mykey => test_123)
【讨论】:
您必须使用它来捕获此类数据:
$log.="http_get_request_body \n";
$entityBody = file_get_contents('php://input');
$log.=print_r($entityBody,true);
$log.="\n----------------\n\n";
感谢@crodas! :)
【讨论】: