2

I'm trying to capture data sent by curl using PHP but it doesn't appear on my end.

I'm executing via console:

curl -d "tests_123" "http://www.example.com/capture.php"

and I have in capture.php

print_r($_POST);
print_r($_GET);
print_r($_REQUEST);

But nothing appears.

Am I doing something wrong?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

You have to use this to capture such data:

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

Thanks to @crodas for this! :)

0

Im sure that you can get the data with $response = file_get_contents('php://input');

However, If you change your command a little bit, and add a key to the value you are sending, you can get the data from your $_POST variable quite easily.

curl -d "Mykey=tests_123" "http://www.example.com/capture.php"

print_r($_POST);
// array ( Mykey => test_123)
mpratt
  • 1,598
  • 12
  • 21