Responses
Responses are the HTTP messages a client receives from a server after sending an HTTP request message.
Start-Line
The start-line of a response contains the protocol and protocol version, status code, and reason phrase.
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'http://httpbin.org/get');
echo $response->getStatusCode(); // 200
echo $response->getReasonPhrase(); // OK
echo $response->getProtocolVersion(); // 1.1
Body
As described earlier, you can get the body of a response using the getBody()
method.
$body = $response->getBody();
echo $body;
// Cast to a string: { ... }
$body->seek(0);
// Rewind the body
$body->read(1024);
// Read bytes of the body