【问题标题】:Capture data sent by curl -d with PHP使用 PHP 捕获 curl -d 发送的数据
【发布时间】: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 capture


【解决方案1】:

我确定你可以通过$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)

【讨论】:

    【解决方案2】:

    您必须使用它来捕获此类数据:

    $log.="http_get_request_body \n";
    $entityBody = file_get_contents('php://input');
    $log.=print_r($entityBody,true);
    $log.="\n----------------\n\n";
    

    感谢@crodas! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-08
      • 2020-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      • 2018-07-07
      相关资源
      最近更新 更多