PHP Post cannot obtain non-form data. Solution: post form

Source: Internet
Author: User

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"}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.