How to deal with PHP Post failing to obtain non-form data

php中世界最好的语言
Release: 2023-03-26 15:46:01
Original
1706 people have browsed it

This time I will show you how to deal with PHP Post that cannot obtain non-form data. What are the things to note when dealing with PHP Post that cannot obtain non-form data? The following is a practical case. Let’s take a look. .

Problem description

When using vue-axios to post data to the backend, the PHP side cannot obtain the posted data.

Problem Solving

Modify php.ini configuration

Find the php.ini

configuration file

, find the enable_post_data_reading variable, and modify it to Open the state, comment out the prefix

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;//输出结果
Copy after login

PS: When posting, the front-end request header must be set to

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

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Detailed explanation of the method of recording search engine crawling process in php


Detailed explanation of the implementation steps of in_array implicit conversion in PHP

The above is the detailed content of How to deal with PHP Post failing to obtain non-form data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!