Fabian
Fabian

Reputation: 53

Guzzle 5 Request as cURL String

is there a way to get the complete Guzzle request as a string like it would be resolved as a cURL request? (Like the "copy as cURL request" option in the dev tools from Chrome or Firefox).

I know there is a library called "Cuzzle" (https://github.com/namshi/cuzzle), but it needs Guzzle 4 and I'm using version 5.

Any tips or help are appreciated. Thanks in advance :)

Fabian

Upvotes: 2

Views: 359

Answers (1)

Pepijn Olivier
Pepijn Olivier

Reputation: 977


Usage (for version 1.2.1, or Guzzle 5, as in OP's original question):

use Namshi\Cuzzle\Formatter\CurlFormatter;
use GuzzleHttp\Message\Request;

$request = new Request('GET', 'example.local');

echo (new CurlFormatter())->format($request);

Upvotes: 1

Related Questions