
guzzle
大家都知道网络请求是网站开发的一个重点,每个语言都有自己的网络请求方式,在网站开发中用到最多的是前端请求什么a标签啊,什么JS的Ajax啊。而有些时候比如做微信支付的时候,我们就会用到PHP发送HTTP请求。而guzzle就是一个封装好的php发起网络请求的工具。
- 可以带参数发送GET和POST请求
- 可以使用Cookie
- 可以发送同步或者异步请求
- 可以做大型文件上传、大型文件下载请求
- 可以通过中间件拓展功能
- 官方地址: https://github.com/guzzle/guzzle
- Start:17083
- Fork:1946
使用
安装
php composer.phar require guzzlehttp/guzzle
简单使用
<?php
require 'vendor/autoload.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();
QQ交流群: 824144151
技术援助
需要技术援助?点击这里,帮你解决你的所有问题!PS:可能你离大神之间,只差一个我们!!!!