php-guzzleHow to get the body in PHP Guzzle?
The body of a response in PHP Guzzle can be obtained using the getBody()
method.
Example code
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'http://www.example.com');
echo $res->getBody();
Output example
<html>
<head>
<title>Example Domain</title>
</head>
<body>
<h1>Example Domain</h1>
<p>This domain is established to be used for illustrative examples in documents. You may use this
domain in examples without prior coordination or asking for permission.</p>
</body>
</html>
Code explanation
$client = new GuzzleHttp\Client();
: This creates a new Guzzle client.$res = $client->request('GET', 'http://www.example.com');
: This sends a GET request to the specified URL.echo $res->getBody();
: This prints the body of the response.
Helpful links
More of Php Guzzle
- How to set a user agent in PHP Guzzle?
- How to set a timeout for a request with PHP Guzzle?
- How to add an SSL certificate to a request with PHP Guzzle?
- How to handle a RequestException with PHP Guzzle?
- How to make an asynchronous send with PHP Guzzle?
- How to convert a response to an array with PHP Guzzle?
- What version of PHP is required for Guzzle?
- How to make HTTP request with PHP Guzzle?
- How to stream with PHP Guzzle?
- How to troubleshoot cURL error 60 with Guzzle in PHP?
See more codes...