2012-03-04 126 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