PHP Post Solution to the problem of not getting non form data

  • 2021-09-12 00:35:34
  • OfStack

Problem description

When using vue-axios to back-end post data, PHP can't get post data.

Problem solving

Modifying php. ini configuration

Find php. ini configuration file, find enable_post_data_reading variable, modify it to open state, and divide it before commenting out sentences


; 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  // Approximately 656 Row, modify this article 

After modifying the configuration, it is found that it is still not working, so continue to consult the data.

Get non-form data

After collecting data, it is found that the non-form data from vue-axios to the back-end post (Ajax is different), and php://input is needed to obtain non-form data


$raw = file_get_contents('php://input');// Get non-form data 
echo $raw;// Output result 

PS: When post, the front-end request header should be set to


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


Related articles: