Get the body of the request

Showing 1-2 of 2 messages
Get the body of the request Adrian Moya 3/31/12 9:59 AM
Hi Michael, is there a way to get the body of a request before sending? I discovered an error in one of my clients I wish to cover with a unit test, so that I can check (as I currently do with the url and the query params) if the body is getting built correctly. Something like:


$this->assertEquals('{"something":"something"}', $command->getRequest()->getRequestBody());

I currently was able to came up with this:

$this->assertEquals('{"something":"something"}', $command->getRequest()->getBody()->read(200));

But I still have to play with lenght to get it right. I plan to implement this test on all my POST commands.

Re: [guzzle] Get the body of the request Michael 3/31/12 10:20 AM
Hi Adrian,

You can read the body as a string by casting the body of the request to string or by calling the __toString method of the request entity body.