今天项目测试php(5.6)报错:
Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set ‘always_populate_raw_post_data’ to ‘-1’ in php.ini and use the php://input stream instead. in Unknown on line 0
查询得知:
在高版本 php 的发版说明中都有 $HTTP_RAW_POST_DATA 即将(已经)取消,请改用从php://input 中读取的声明
修改php.ini配置文件即可:
always_populate_raw_post_data = -1
知识点: $HTTP_RAW_POST_DATA
是什么鬼?
问题: $HTTP_RAW_POST_DATA == $_POST 吗?
回答:否
解释:
手册解释如下:
The RAW / uninterpreted HTTP POst information can be accessed with:
$GLOBALS[‘HTTP_RAW_POST_DATA’]
This is useful in cases where the post Content-Type is not something PHP understands (such as text/xml).
基本上$GLOBALS['HTTP_RAW_POST_DATA']
和 $_POST
是一样的。
但是如果post过来的数据不是PHP能够识别的,你可以用 $GLOBALS['HTTP_RAW_POST_DATA']
来接收,比如text/xml
或者 soap
等等。
PHP默认识别的数据类型是application/x-www.form-urlencoded
标准的数据类型。
用Content-Type=text/xml
类型,提交一个xml文档,php端要怎么获得这个POST数据?
The RAW / uninterpreted HTTP POST information can be accessed with: $GLOBALS[‘HTTP_RAW_POST_DATA’] This is useful in cases where the post Content-Type is not something PHP understands (such as text/xml).
型如text/xml
的内容无法解析为$_POST
数组,故保留原型,交给$GLOBALS['HTTP_RAW_POST_DATA']
来接收,另外还有一项 php://input
也可以实现此这个功能
php://input
允许读取 POST
的原始数据。和 $HTTP_RAW_POST_DATA
比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini
设置。
php://input
不能用于 enctype="multipart/form-data"
。
end~