Extracting JSON Post Body in PHP
Consider the following JSON POST data:
In PHP, the default $_POST variable will not contain this data. Instead, access the raw HTTP request body using:
Alternatively, use the STDIN constant:
Note that php://input is unseekable and can only be read once. For large bodies, consider using a temporary file to maintain the stream resource:
Exceptions occur when specifying a "multipart/form-data" header in the POST request, as PHP already parses this data into the $_POST superglobal.
The above is the detailed content of How to Extract a JSON POST Body in PHP?. For more information, please follow other related articles on the PHP Chinese website!