Home > Backend Development > PHP Problem > What should I do if php cannot get the post?

What should I do if php cannot get the post?

藏色散人
Release: 2023-03-02 09:06:01
Original
3325 people have browsed it

The solution to the problem that php cannot obtain the post: first check the header information "content-type"; then use "file_get_contents("php://input")" to obtain the input stream to receive the post data.

What should I do if php cannot get the post?

php cannot get the value of post

This usually occurs when submitting ajax

When we set the ajax parameter contentType: 'application/json; charset=utf-8', we cannot get the value $_POST using file_get_contents("php://input")

1 .Check whether the content-type of the header information is "content-type:application/x-www-form-urlencoded". This transmission is to submit data in a form and PHP uses $_POST to accept it.

2. If the content-type of the header information is "content-type:application/json", the transmission is to submit data in json mode, and PHP needs to use file_get_contents("php://input") to obtain it. The input stream method accepts

For more related knowledge, please visit PHP Chinese website!

The above is the detailed content of What should I do if php cannot get the post?. 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