Joel D
Joel D

Reputation: 290

Guzzle 5 - Get Response Body on ServerException

I am using Guzzle (latest 5.2) to do a POST call to a server. The API on this server returns a "HTTP/1.1 500 Internal Server Error" response, but also returns a body. How do I get access to the body of the response from the exception?

Below is what I get when I do the POST with curl -v:

* upload completely sent off: 826 out of 826 bytes
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 24 Feb 2015 01:57:10 GMT
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Content-Type: application/xml
< Content-Length: 154
< Connection: close
<
* Closing connection 0
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><addressList xmlns:ns2="http://addresslistserver.c2m.com/"><status>9</status><lists/></addressList>

Upvotes: 4

Views: 1604

Answers (1)

Joel D
Joel D

Reputation: 290

I've discovered a solution:

$exception->getResponse()->getBody()

Could have sworn I tried that hours ago and it didn't work, but I guess not.

Upvotes: 7

Related Questions