Guzzlehttp: How to Retrieve Body from Response (Guzzle 6)
In Guzzle 6, the response body is stored in a PSR-7 compliant stream, which is a temporary PHP stream. To retrieve the response body as a string, use one of the following methods:
1. Casting Operator:
$contents = (string) $response->getBody();
2. getContents() Method:
$contents = $response->getBody()->getContents();
Difference between the two methods:
Example Response Output:
{ "data" : { "token" "fasdfasf-asfasdfasdf-sfasfasf" } }
Additional Notes:
The above is the detailed content of Guzzle 6: How Do I Get the Response Body as a String?. For more information, please follow other related articles on the PHP Chinese website!