Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guzzle 6, get request string

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.

like image 610
Nicekiwi Avatar asked Sep 13 '15 23:09

Nicekiwi


People also ask

How do I get data from Guzzle response?

You can check to see if a request or response has a body using the getBody() method: $response = GuzzleHttp\get('http://httpbin.org/get'); if ($response->getBody()) { echo $response->getBody(); // JSON string: { ... } }

How do I send a POST request with Guzzle?

Sending Requests You can create a request and then send the request with the client when you're ready: use GuzzleHttp\Psr7\Request; $request = new Request('PUT', 'http://httpbin.org/put'); $response = $client->send($request, ['timeout' => 2]);

How do I debug Guzzle request?

Debugging when using Guzzle, is quiet easy by providing the debug key in the payload: $client->request('GET', '/url, ['debug' => true]); This is quiet easy and not an issue if your are not passing any body content, using only query string to dump what's been request.

Is Guzzle better than cURL?

The main benefits of using Guzzle over cURL is the API it offers, which results in more concise and readable code. For example look at the difference between the code in this question and the accepted answer, the cURL code is much more verbose that the Guzzle implementation.


1 Answers

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]); 
like image 162
Mohammed Safeer Avatar answered Oct 11 '22 18:10

Mohammed Safeer