Guzzlehttp - How to get the body of a response from Guzzle 6? 1


 

Guzzlehttp-How-to-get-the-body-of-a-response-from-Guzzle-6-Laravel

 

If you are using Guzzle HTTP to call an API in Laraval:

 

           $client = new \GuzzleHttp\Client();

            $response = $client->request('POST', 'https://ctells.com/tx/api/getTxFailed');

 

Use the following code to get a response in JSON or to print a value of a key:

 

          $data = json_decode($response->getBody(), true);

            echo $data['name'];

 

To print complete response use the following code:

 

echo $response->getBody();