Home>Article>Backend Development> How to deal with PHP Post failing to obtain non-form data

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

php中世界最好的语言
php中世界最好的语言 Original
2018-05-18 14:21:51 1634browse

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

; 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: When posting, the front-end request header must be set to

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

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!

Statement:
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