Byron Whitlock
Byron Whitlock

Reputation: 53871

How do I debug web services when using Zend_Rest_Client

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?

Upvotes: 2

Views: 1036

Answers (3)

foufos
foufos

Reputation:

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);

Upvotes: 0

Ionuț G. Stan
Ionuț G. Stan

Reputation: 179139

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.

Upvotes: 4

Byron Whitlock
Byron Whitlock

Reputation: 53871

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

Upvotes: 0

Related Questions