安装
使用composer安装:
composer require guzzlehttp/guzzle
或者编辑项目的composer.json文件,添加guzzle作为依赖:
"require": {
....
"guzzlehttp/guzzle": "~6.0"
},
然后执行composer update
二、guzzle基本使用
发送请求
use GuzzleHttp\Client;
$client = new Client([
//跟域名
'base_uri' => 'http://localhost/test',
// 超时
'timeout' => 2.0,
]);
$response = $client->get('/get'); //http://localhost/get
$response = $client->delete('delete'); //http://localhost/get/delete
$response = $client->head('http://localhost/get');
$response = $client->options('http://localhost/get');
$response = $client->patch('http://localhost/patch');
$response = $client->post('http://localhost/post');
$response = $client->put('http://localhost/put');
post
$response = $client->request('POST', 'http://localhost/post', [
'form_params' => [
'username' => 'webben',
'password' => '123456',
'multiple' => [
'row1' => 'hello'
]
]
]);