php 未定义变量:HTTP_RAW_POST_DATA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9553168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undefined variable: HTTP_RAW_POST_DATA
提问by Sarmen B.
when I do a simple echo of $HTTP_RAW_POST_DATA i get the error:
当我做一个简单的 $HTTP_RAW_POST_DATA 回显时,我收到错误:
Undefined variable: HTTP_RAW_POST_DATA
I read that in php.ini i need to un-tick
我在 php.ini 中读到,我需要取消勾选
always_populate_raw_post_data = On
but i still get the error and I did restart Apache as well. Im using php 5.3.6
但我仍然收到错误,我也重新启动了 Apache。我使用 php 5.3.6
回答by rdlowrey
If you need to access the raw POST body you should really favor the use of the php://input
stream over $HTTP_RAW_POST_DATA
as per the relevant manual entry:
如果您需要访问原始 POST 正文,您应该真正赞成根据相关手册条目使用php://input
流:$HTTP_RAW_POST_DATA
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".
php://input 是一个只读流,允许您从请求正文中读取原始数据。对于 POST 请求,最好使用 php://input 而不是 $HTTP_RAW_POST_DATA,因为它不依赖于特殊的 php.ini 指令。此外,对于默认情况下未填充 $HTTP_RAW_POST_DATA 的那些情况,它是激活 always_populate_raw_post_data 的潜在内存密集型替代方案。php://input 不适用于 enctype="multipart/form-data"。
So, to access the POST body using php://input
:
因此,要使用以下方法访问 POST 正文php://input
:
$post = file_get_contents('php://input');
回答by Milap
If you get
如果你得到
Notice: Undefined variable: HTTP_RAW_POST_DATA
注意:未定义变量:HTTP_RAW_POST_DATA
Please open your Server file add find
请打开您的服务器文件添加查找
$server->service($HTTP_RAW_POST_DATA);
and replace with following 2 lines.
并替换为以下 2 行。
if ( !isset( $HTTP_RAW_POST_DATA ) ) $HTTP_RAW_POST_DATA =file_get_contents( 'php://input' );
$server->service($HTTP_RAW_POST_DATA);
I hope this would help.
我希望这会有所帮助。