2015-02-24 37 views
1

我正在使用Guzzle(最新的5.2)對服務器執行POST調用。此服務器上的API返回「HTTP/1.1 500內部服務器錯誤」響應,但也返回一個正文。如何訪問異常響應的主體?Gu 5 5 - 在ServerException上獲取響應正文

下面是我所得到的,當我做捲曲-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> 

回答

1

,我發現了一個解決方案:

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

可以發誓我小時前試過了,它沒有工作,但我猜不是。