365Tools
发布时间:2025-12-15 10:50:56
Guzzle 是一款简单、易用的 PHP HTTP 客户端。
它可以快速的集成到 WEB 项目中,帮助我们非常方便的发送 HTTP 请求。
Guzzle 特点
接口简单
支持使用 curl,PHP streams,sockets等各种方式。
支持同步和异步请求
遵循 PSR7 规范,可以集成其他的符合 psr7 规范的类库,自定义处理逻辑
composer require guzzlehttp/guzzle
1. 简单使用
$response = (new Client(['verify' => false]))->request('post',$api);
$content = trim($response->getBody()->getContents(),PHP_EOL);
2. 发送表单请求
$client->request('POST', '/post', [
'form_params' => [
'user_id' => 1,
'user_name' => 'hello world!'
]
]);
3. 发送BODY请求
$response = (new Client(['verify' => false]))->request('post', $api, ['body' => $body, 'headers' => $headers]);
$contents = $response->getBody()->getContents();
附件: