cvreferral / guzzle
Guzzle 是一个 PHP HTTP 客户端库
dev-master / 6.1.x-dev
2020-12-31 07:44 UTC
Requires
- php: >=5.5.0
- guzzlehttp/promises: ~1.0
- guzzlehttp/psr7: ~1.1
Requires (Dev)
- ext-curl: *
- phpunit/phpunit: ~4.0
- psr/log: ~1.0
This package is auto-updated.
Last update: 2024-09-29 06:02:49 UTC
README
Guzzle 是一个 PHP HTTP 客户端,使得发送 HTTP 请求变得简单,并与 Web 服务轻松集成。
- 提供了构建查询字符串、POST 请求、大文件上传和下载、使用 HTTP Cookie、上传 JSON 数据等操作的简单接口...
- 可以使用相同的接口发送同步和异步请求。
- 使用 PSR-7 接口进行请求、响应和流处理。这允许您使用其他 PSR-7 兼容库与 Guzzle 一起使用。
- 抽象了底层的 HTTP 传输,允许您编写与环境和服务无关的代码;即,不需要对 cURL、PHP 流、套接字或非阻塞事件循环有硬依赖。
- 中间件系统允许您增强和组合客户端行为。
$client = new GuzzleHttp\Client(); $res = $client->request('GET', 'https://api.github.com/user', [ 'auth' => ['user', 'pass'] ]); echo $res->getStatusCode(); // 200 echo $res->getHeader('content-type'); // 'application/json; charset=utf8' echo $res->getBody(); // {"type":"User"...' // Send an asynchronous request. $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org'); $promise = $client->sendAsync($request)->then(function ($response) { echo 'I completed! ' . $response->getBody(); }); $promise->wait();
帮助和文档
安装 Guzzle
推荐通过 Composer 安装 Guzzle。
# Install Composer curl -sS https://getcomposer.org/installer | php
接下来,运行 Composer 命令安装最新稳定的 Guzzle 版本
composer.phar require guzzlehttp/guzzle
安装后,您需要引入 Composer 的自动加载器
require 'vendor/autoload.php';
然后您可以使用 composer 更新 Guzzle
composer.phar update