PHP 获取 POST 数据,请使用 php://input,不要使用 $HTTP_RAW_POST_DATA

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/henryhu712/article/details/82682805

请使用下面这个方式来获取 POST 数据:

$post = file_get_contents('php://input');

关于两者的区别,官方解释如下:

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”.

猜你喜欢

转载自blog.csdn.net/henryhu712/article/details/82682805