How to solve the problem that php cannot obtain form data

WJ
Release: 2023-03-01 14:24:01
Original
4278 people have browsed it

How to solve the problem that php cannot obtain form data

How to solve the problem that php cannot obtain form data?

Problem Solving Modify php.iniConfiguration

Find the php.ini configuration file, find the enable_post_data_reading variable, and modify it to the open state. Comment out the sentence 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行,修改此条
Copy after login

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:post时前端请求头要设置为
headers: {    "Content-type": "application/json; charset=utf-8"}
Copy after login

Related recommendations:php tutorial

The above is the detailed content of How to solve the problem that php cannot obtain form data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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!