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.
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!