2012-03-04 139 views
14

當我做的$一個簡單的回聲HTTP_RAW_POST_DATA我得到的錯誤:未定義的變量:HTTP_RAW_POST_DATA

Undefined variable: HTTP_RAW_POST_DATA 

,我讀了在php.ini我需要取消選中

always_populate_raw_post_data = On 

但我仍然得到錯誤,我也重新啓動了Apache。即時通訊使用PHP 5.3.6

+0

您是否對任何Web服務使用任何HTTP_RAW_POST_DATA? – Milap 2012-03-04 07:38:57

+0

在這個例子中,不,但我創始性地關注這個頁面http://phpmaster.com/web-services-with-php-and-soap-1/並得到了錯誤,所以我創建了一個頁面來調查錯誤。 – 2012-03-04 07:41:01

回答

24

如果您需要訪問原始POST體你真的應該傾向於使用php://input流過$HTTP_RAW_POST_DATA按照該relevant manual entry

php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".

因此,訪問POST體使用php://input

$post = file_get_contents('php://input'); 
+0

謝謝,當我讀到undefined時,我確實看到了這個,但是沒有想到使用它。但我錯了,謝謝! – 2012-03-04 07:46:39

19

如果你

Notice: Undefined variable: HTTP_RAW_POST_DATA

請打開你的服務器文件中添加找到

$server->service($HTTP_RAW_POST_DATA); 

,並與下面的2行更換。

if (!isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA =file_get_contents('php://input'); 
$server->service($HTTP_RAW_POST_DATA); 

我希望這會有所幫助。

+0

謝謝一位男士... – San 2012-10-18 20:45:59

+0

歡迎您。享受.. @San – Milap 2012-10-19 06:18:09

+0

米拉普你有什麼想法如何得到PHP腳本的反應,因爲我用肥皂服務,它運行良好,搜索了很多文章,他們建議我實現AJAX,PHP是服務器端,我想以獲得它的迴應,以便我可以在我的HTML格式中使用它... – San 2012-10-19 08:03:46