Home > Backend Development > PHP Tutorial > How to receive json data in php

How to receive json data in php

清浅
Release: 2023-04-06 14:32:01
Original
16461 people have browsed it

PHP can receive json data through the file_get_contents method. When receiving such a request, the bottom layer of php will parse the string into the $_POST variable, and then obtain the json data through this variable

How to receive json data in php

PHP receives json dataIt can be obtained in the following ways in PHP:

file_get_contents("php://input"); 
Copy after login

Analysis:

php does web page form submission

In the early years of web form submission, $_POST was used to obtain request parameters. In fact, the http request header was in the form of kv value, such as:

How to receive json data in php

#When php receives this kind of request, the php underlying system will parse this string and store it in the $_POST variable, so you can pass $_POST in php Get these parameters.

Upload file http request header

Content-Type has changed to multipart/form-data format. Data acquisition in this format is also processed at the bottom of PHP. Ordinary non-file parameters can also be obtained through $_POST, and file parameters can be obtained through $_FILES.

php gets json format data

The json format data refers to the http header body string which is a json format string. This cannot be obtained through $_POST in PHP, and the bottom layer of PHP does not handle this method. After obtaining the data in the body, you can directly json_decode to get the data in object format.

The above is the detailed content of How to receive json data in php. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template