Accessing JSON POST Body in PHP
In PHP, accessing the JSON body of a POST request requires a specific method. While $_POST cannot handle JSON data, the php://input stream can be utilized to retrieve it.
To obtain the body of a JSON POST request, follow these steps:
$requestBody = file_get_contents('php://input'); // or stream_get_contents(STDIN)
$data = json_decode($requestBody);
$value = $data->a; // In your example, this would be 1
Note:
The above is the detailed content of How Do I Access a JSON POST Body in PHP?. For more information, please follow other related articles on the PHP Chinese website!