未定义的变量:HTTP_RAW_POST_DATA
当我做的$一个简单的回声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
如果您需要访问原始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');
谢谢,当我读到undefined时,我确实看到了这个,但是没有想到使用它。但我错了,谢谢! – 2012-03-04 07:46:39
如果你
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);
我希望这会有所帮助。
您是否对任何Web服务使用任何HTTP_RAW_POST_DATA? – Milap 2012-03-04 07:38:57
在这个例子中,不,但我创始性地关注这个页面http://phpmaster.com/web-services-with-php-and-soap-1/并得到了错误,所以我创建了一个页面来调查错误。 – 2012-03-04 07:41:01