Guzzle 5请求为cURL字符串

问题描述 投票:2回答:1

有没有办法把完整的Guzzle请求作为一个字符串,就像它将被解析为cURL请求一样? (例如Chrome或Firefox的开发工具中的“复制为cURL请求”选项)。

我知道有一个名为“Cuzzle”(https://github.com/namshi/cuzzle)的库,但它需要Guzzle 4而我使用的是版本5。

任何提示或帮助表示赞赏。提前致谢 :)

法比安

php curl guzzle
1个回答
0
投票

用法(对于版本1.2.1,或Guzzle 5,如OP的原始问题):

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

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

echo (new CurlFormatter())->format($request);
© www.soinside.com 2019 - 2024. All rights reserved.