我正在使用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>
解决方法:
我发现了一个解决方案:
$exception->getResponse()->getBody()
可能已经发誓我几个小时前就试过了它并没有用,但我猜不是.