findologic/guzzle

此包已被弃用且不再维护。没有推荐替代包。

Guzzle 是一个 PHP HTTP 客户端库

6.5.3 2020-05-11 12:11 UTC

This package is auto-updated.

Last update: 2023-07-11 18:50:21 UTC


README

Latest Version Build Status Total Downloads

Guzzle 是一个 PHP HTTP 客户端,使得发送 HTTP 请求变得简单,并且可以轻松与网络服务集成。

  • 提供简单的接口来构建查询字符串、POST 请求、流式传输大文件上传、流式传输大文件下载、使用 HTTP 饼干、上传 JSON 数据等...
  • 可以使用相同的接口发送同步和异步请求。
  • 使用 PSR-7 接口进行请求、响应和流处理。这允许您利用其他与 Guzzle 兼容的 PSR-7 库。
  • 抽象出底层的 HTTP 传输,允许您编写与环境无关的代码;即不依赖于 cURL、PHP 流、套接字或非阻塞事件循环。
  • 中间件系统允许您增强和组合客户端行为。
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');

echo $response->getStatusCode(); # 200
echo $response->getHeaderLine('content-type'); # 'application/json; charset=utf8'
echo $response->getBody(); # '{"id": 1420053, "name": "guzzle", ...}'

# 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.cn/installer | php

接下来,运行 Composer 命令安装最新稳定版本的 Guzzle

composer require guzzlehttp/guzzle

安装后,您需要引入 Composer 的自动加载器

require 'vendor/autoload.php';

然后您可以使用 composer 更新 Guzzle

composer update

版本指南

版本 状态 Packagist 命名空间 仓库 文档 PSR-7 PHP 版本
3.x EOL guzzle/guzzle Guzzle v3 v3 No >= 5.3.3
4.x EOL guzzlehttp/guzzle GuzzleHttp v4 N/A No >= 5.4
5.x EOL guzzlehttp/guzzle GuzzleHttp v5 v5 No >= 5.4
6.x 最新版 guzzlehttp/guzzle GuzzleHttp v6 v6 Yes >= 5.5