How to solve the problem that php cannot obtain form data?
Problem Solving Modify php.ini
Configuration
Find the php.ini configuration file, find the enable_post_data_reading
variable, and modify it to the open state. Comment out the sentence prefix
; 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行,修改此条
After modifying the configuration, I found that it still didn't work, so I continued to check the information.
Getting non-form data
After collecting information, I found that vue-axios posts non-form data to the backend (different from Ajax). You need to use php://input when getting non-form data.
$raw = file_get_contents('php://input');//获取非表单数据echo $raw;//输出结果 PS:post时前端请求头要设置为 headers: { "Content-type": "application/json; charset=utf-8"}
Related recommendations:php tutorial
The above is the detailed content of How to solve the problem that php cannot obtain form data. For more information, please follow other related articles on the PHP Chinese website!