2013-05-29 70 views
2

我试图捕获使用PHP通过curl发送的数据,但它并未出现在我的末尾。使用PHP通过curl -d发送捕获的数据

我通过控制台执行:

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

和我有capture.php

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

但似乎什么都没有。

我做错了什么?

+0

完全在http://stackoverflow.com/questions/664148/how-to-access-post-data-in-php – maxpolk

回答

0

我确信,你可以用$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) 
0

你必须使用此捕获这样的数据:

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

感谢@crodas这个! :)