一、php://input 介绍
官网原话:
php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype=”multipart/form-data
php://input 可以读取没有处理过的POST数据。相较于$HTTP_RAW_POST_DATA而言,它给内存带来的压力较小,并且不需要特殊的php.ini设置,但是 php://input 不能用于 enctype=multipart/form-data
二、注意点与区别
根据请求头的 Content-Type 进行区分
1)Content-Type = application/x-www-data-urlencoded
HTTP请求的数据存入$_POST
php://input 数据与 $_POST 一致,其他情况都不一致
2)Content-Type = multipart/form-data
HTTP请求的数据存入$_POST
HTTP请求数据包中的相应数据不会填入php://input,否则其它情况都会
3)当 Content-Type 不可识别时
HTTP请求数据会存入$HTTP_RAW_POST_DATA
注意:php://input 数据总是跟 $HTTP_RAW_POST_DATA 相同,但是 php://input 比 $HTTP_RAW_POST_DATA 更有效,且不需要特殊设置php.ini
三、使用 php://input 接受post数据
$post_content = file_get_contents("php://input");