Guzzle中文文档
Guzzle是一个PHP的HTTP客户端,用来轻而易举地发送请求,并集成到我们的WEB服务上。
- 接口简单:构建查询语句、POST请求、分流上传下载大文件、使用HTTP cookies、上传JSON数据等等。
- 发送同步或异步的请求均使用相同的接口。
- 使用PSR-7接口来请求、响应、分流,允许你使用其他兼容的PSR-7类库与Guzzle共同开发。
- 抽象了底层的HTTP传输,允许你改变环境以及其他的代码,如:对cURL与PHP的流或socket并非重度依赖,非阻塞事件循环。
- 中间件系统允许你创建构成客户端行为。
1. $client = new GuzzleHttp\Client();
2. $res = $client->request('GET', 'https://api.github.com/user', [
3. 'auth' => ['user', 'pass']
4. ]);
5. echo $res->getStatusCode();
6. // "200"
7. echo $res->getHeader('content-type');
8. // 'application/json; charset=utf8'
9. echo $res->getBody();
10. // {"type":"User"...'
12. // 发送一个异步请求
13. $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
14. $promise = $client->sendAsync($request)->then(function ($response) {
15. echo 'I completed! ' . $response->getBody();
16. });
17. $promise->wait();
用户指南
- 概述
- 需求
- 安装
- 许可证
- 贡献
- 报告安全漏洞
- 快速入门
- 发送请求
- 使用响应
- 查询字符串参数
- 上传数据
- Cookies
- 重定向
- 异常
- 环境变量
- 请求选项
- allow_redirects
- auth
- body
- cert
- cookies
- connect_timeout
- debug
- decode_content
- delay
- expect
- form_params
- headers
- http_errors
- json
- multipart
- on_headers
- on_stats
- proxy
- query
- sink
- ssl_key
- stream
- synchronous
- verify
- timeout
- version
- Guzzle and PSR-7
- Headers
- Body
- Requests
- Responses
- Streams
- Handlers and Middleware
- Handlers
- Middleware
- HandlerStack
- Creating a Handler
- Testing Guzzle Clients
- Mock Handler
- History Middleware
- Test Web Server
- FAQ
- Does Guzzle require cURL?
- Can Guzzle send asynchronous requests?
- How can I add custom cURL options?
- How can I add custom stream context options?
- Why am I getting an SSL verification error?
- What is this Maximum function nesting error?
- Why am I getting a 417 error response?
