处理PHP Post猎取不到非表单数据的题目

个人博客同步文章
https://mr-houzi.com/2018/02/…

题目形貌

在运用vue-axios向后端post数据时,PHP端猎取不到post的数据。

题目解决

修正php.ini设置

找到php.ini设置文件,查找enable_post_data_reading变量,修正为翻开状况,解释掉句前分好

; Whether PHP will read the POST data.
; This option is enabled by default.
; Most likely, you won't want to disable this option globally. It causes $_POST
; and $_FILES to always be empty; the only way you will be able to read the
; POST data will be through the php://input stream wrapper. This can be useful
; to proxy requests or to process the POST data in a memory efficient fashion.
; http://php.net/enable-post-data-reading
enable_post_data_reading = On    //约莫656行,修正此条

修正设置后,发明照样不可,继承查阅材料。

猎取非表单数据

汇集材料以后,发明vue-axios向后端post的黑白表单数据(Ajax差别),在猎取非表单数据时需要用php://input

$raw = file_get_contents('php://input');//猎取非表单数据
echo $raw;//输出效果

PS:post时前端要求头要设置为

headers: {
    "Content-type": "application/json; charset=utf-8"
}

参考文章:
[1]http://blog.csdn.net/whd526/a…
[2]https://segmentfault.com/q/10…

    原文作者:Mr_houzi
    原文地址: https://segmentfault.com/a/1190000013400250
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞