狂饮5-在ServerException上获取响应正文

Joe*_*l D 4 php guzzle

我正在使用Guzzle(最新版本5.2)对服务器进行POST调用。此服务器上的API返回“ HTTP / 1.1 500内部服务器错误”响应,但还返回正文。如何从异常中访问响应的正文?

以下是我使用curl -v执行POST时得到的结果:

* 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>
Run Code Online (Sandbox Code Playgroud)

Joe*_*l D 6

我发现了一个解决方案:

$exception->getResponse()->getBody()
Run Code Online (Sandbox Code Playgroud)

我可能在几个小时前就宣誓就发誓,但没有成功,但我想没有。