0
我已經歷了this post的所有迴應
print_r($ _ POST); ===>返回空數組
print_r($ _ SERVER);
Array ([HTTP_HOST] => localhost
[HTTP_ACCEPT] => */*
**[HTTP__CONTENT_TYPE]** => application/json; charset=UTF-8"
[CONTENT_LENGTH] => 942
**[CONTENT_TYPE]** => application/x-www-form-urlencoded
[PATH] => /usr/local/bin:/usr/bin:/bin
[SERVER_SIGNATURE] => Apache/2.2.14 (Ubuntu) Server at localhost Port 80
[SERVER_SOFTWARE] => Apache/2.2.14 (Ubuntu)
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /var/www
[SERVER_ADMIN] => [email protected]
[SCRIPT_FILENAME] => /var/www/slocation.php
[REMOTE_PORT] => 50657
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] =>
[REQUEST_URI] => /slocation.php
[SCRIPT_NAME] => /slocation.php
[PHP_SELF] => /slocation.php
[REQUEST_TIME] => 1288466907
)
HTTP__CONTENT_TYPE和CONTENT_TYPE有什麼區別?
print_r($ HTTP_RAW_POST_DATA); ==>返回正確的數據
file_get_contents('php:// input'); ======>返回正確的數據。
只有$ _POST失敗。
這是我的curl命令
$url = "http://localhost/slocation.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array('"Content-type: application/json; charset=UTF-8"'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($ch);
UPDATE ::::::::::::::::::::::::::::::::: :::::::::::::::::
我發現了一個主here
'$ payload'包含什麼? – 2010-10-30 19:47:15
更重要的是,你期望'$ _POST'包含什麼? – 2010-10-30 19:48:03
嘿Pekka! $ payload包含一個json字符串。但我嘗試將一個簡單的「hello」作爲POST數據和「text/html」作爲Content-Type標頭傳遞。但$ _POST總是空的。我希望$ _POST具有與我傳入的數據相同的數據。 $ _POST = $ HTTP_RAW_POST_DATA = file_get_contents('php:// input'); – 2010-10-30 19:54:44