hanwenbo / fetch
FaShop EasySwoole HttpClient
1.0.1
2022-10-08 06:44 UTC
Requires
- php: >=7.4
- easyswoole/http-client: ^1.5
Requires (Dev)
- ext-json: *
- easyswoole/swoole-ide-helper: ^1.2
README
该类主要是为了解决第三方包用了guzzle基础请求方法保持一致,又能使用EasySwoole
安装
composer require hanwenbo/fetch
测试
php tests/fetch.php
要在
swoole
环境下运行,根目录的docker-compose.yml
是写项目经常用到的docker环境 docker-compose up -d docker-compose exec swoole bash composer install php tests/fetch.php
示例代码
GET
$client = new \hanwenbo\fetch\Fetch(); $res = $client->request( 'GET', 'https://www.baidu.com', [ 'header'=>[ 'test'=>1 ], 'query' => [ 'adada' => 121212, ], ] );
POST
form请求
$client = new \hanwenbo\fetch\Fetch(); $res = $client->request( 'POST', 'https://www.baidu.com', [ 'header'=>[ 'test'=>1 ], 'form_params' => [ 'adada' => 121212, ], ] );
json请求
$client = new \hanwenbo\fetch\Fetch(); $res = $client->request( 'POST', 'https://www.baidu.com', [ 'header'=>[ 'test'=>1 ], 'body' => [ 'adada' => 121212, ], ] );
其他的
PUT
DELETE
PATCH
参考POST
即可