PHP Post cannot obtain non-form data. Solution: post form
Problem description
When you use vue-axios to post data to the backend, PHP cannot obtain the post data.
Problem Solving
Modify php. ini configuration
Find the php. ini configuration file, find the enable_post_data_reading variable, change it to the open state, and comment out the sentence.
; 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-readingenable_post_data_reading = On // about 656 rows, modify this
After the configuration is modified, it still does not work. Continue to check the information.
Retrieve non-form data
After collecting the information, we found that vue-axios post non-form data to the backend (Ajax is different). When obtaining non-form data, we need to use php: // input
$ Raw = file_get_contents ('php: // input'); // obtain non-form data echo $ raw; // output the result
PS: The frontend Request Header must be set
headers: { "Content-type": "application/json; charset=utf-8"}