views:

95

answers:

3

So I have an app that uses the Zend amazon web services client. I am now getting an error from the service, and I want to see the raw request and response.

I can't find a way to do this in the docs! This class implements Zend_Rest_Client so it seems like there should be a rawResponse() method but there isn't. This is on a production server and I am behind a firewall, so I can't proxy to fiddler.

Any suggestions?

A: 

So the answer is to overload the amazon class, and print out the $response->getBody() method in ItemSearch/ItemLookup

Byron Whitlock
+1  A: 

Zend_Rest_Client extends Zend_Service_Abstract, which in turn implements a getHttpClient() method, which returns a Zend_Http_Client instance, which exposes a getLastResponse() method, which returns a Zend_Http_Response instance, which once again exposes a getBody() method. Phew, that's OOP I guess :).

Let's talk our language though:

$restClient->getHttpClient()->getLastResponse()->getBody();

That's it.

EDIT:

It appears that Zend_Service_Abstract::getHttpClient() is static, so you can even call it like this:

Zend_Service_Abstract::getHttpClient()->getLastResponse()->getBody();

But I wouldn't recommend it. You have to know exactly when to call the method, as the HTTP client must be populated with some response. Not to mention that static methods are just some kind of globals, which is bad.

Ionuț G. Stan
That is so sweet. Thanks.
Byron Whitlock
A: 

if you would like to view the actual xml received, then you should:
$actual_xml = htmlentities($client->getHttpClient()->getLastResponse()->getBody());
echo $actual_xml;

note.
if you want to write this to a file, then use htmlspecialchars_decode($actual_xml);

foufos