2013-05-29 75 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這個! :)