hanwenbo/fetch

FaShop EasySwoole HttpClient

1.0.1 2022-10-08 06:44 UTC

This package is auto-updated.

Last update: 2024-04-08 10:03:55 UTC


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 即可

其他