文档:
- https://guzzle-cn.readthedocs.io/zh_CN/latest/
- https://packagist.org/packages/guzzlehttp/guzzle
- https://docs.guzzlephp.org/en/stable/
安装
composer require guzzlehttp/guzzle
发送GET请求
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();
$response = $client->get('http://httpbin.org/get', [
'query' => [
'name' => 'Tom'
]
]);
echo $response->getStatusCode(); // 200
$content = $response->getBody()->getContents();
print_r($content);
发送POST请求
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$client = new Client();
$response = $client->post('http://httpbin.org/post', [
'json' => [
'name' => 'Tom'
]
]);
echo $response->getStatusCode(); // 200
$content = $response->getBody()->getContents();
print_r($content);