Guzzle 6, get request string

Nicekiwi picture Nicekiwi · Sep 14, 2015 · Viewed 28.2k times · Source

Is there a way I can print out the full request as a string before or after it is sent?

$res = (new GuzzleHttp\Client())->request('POST', 'https://endpoint.nz/test', [ 'form_params' => [ 'param1'=>1,'param2'=>2,'param3'=3 ] ] );

how can I view that request as a string? (not the response)

The reason is, my request is failing and returning a 403, and I want to know what exactly is being sent; as the same request works when using PostMan.

Answer

Mohammed Safeer picture Mohammed Safeer · Sep 14, 2015

As per Guzzle documentation there is debug option, here is the link from guzzle documentation http://guzzle.readthedocs.org/en/latest/request-options.html#debug

$client->request('GET', '/get', ['debug' => true]);