方法一,$_post

$_post或$_request存放的是php以key=>value的形式格式化以后的数据。

方法二,使用file_get_contents(“php://input”)

对于未指定 content-type 的post数据,则可以使用file_get_contents(“php://input”);来获取原始数据。

事实上,用php接收post的任何数据均使用本方法。而不用考虑content-type,包括二进制文件流也是可行的。

同$http_raw_post_data比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini 设置。

php://input无法读取content-type为multipart/form-data的post数据,需要设置php.ini中的
always_populate_raw_post_data值为on才可以。

php://input读取不到$_get数据。是因为$_get数据作为query_path写在http请求头部(header)的path字段,而不是写在http请求的body部分。

方法三,使用全局变量$globals[‘http_raw_post_data’]

在$globals[‘http_raw_post_data’]存放的是post过来的原始数据。

但$globals[‘http_raw_post_data’]中是否保存post过来的数据取决于centent-type的设置,只有在php在无法识别的content-type的情况下,才会将post过来的数据原样地填入变量$globals[‘http_raw_post_data’]中,象content-type=
application/x-www-form-urlencoded时,该变量是空的。

另外,它同样无法读取content-type为multipart/form-data的post数据,也需要设置php.ini中的
always_populate_raw_post_data值为on,php才会总把post数据填入变量$http_raw_post_data。