0
votes

I'm making a Guzzle request to an api, and

$request = $this->client->request('GET', 'https://etc', ['http_errors' => false]);

I've had to turn http_errors off as if the API wants to tell me something it does it as a JSON response but it also has a header code of 402.

I can get the response headers back from Guzzle, but I'm unable to get the actual body $request->getBody() as this is just an empty stream on the response object.

Does anyone know how I retrieve the original page despite it providing a 402 http error.

NB: If I don't turn off http_errors, it will throw an exception but the message is wrapped (and truncated).

Any suggestions would be gratefully received.

1

1 Answers

3
votes

I stumbled across the answer I was looking for.

If I don't turn off http_errors and catch the exception I can run

$e->getResponse()->getBody()->getContents();

to retrieve the contents of the request.