个人博客同步文章
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…