rokde / http-client
此软件包已被放弃,不再维护。未建议替代软件包。
一个无任何依赖的 http 客户端库。仅使用纯 PHP。
1.1.0
2019-03-14 16:18 UTC
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^7.2
README
此 http 客户端库不依赖 curl 或 guzzle 等软件。它使用纯 PHP 函数处理最常用的 http 请求。
安装
composer require rokde/http-client
使用
您有两个选项
- 使用辅助函数
http()
- 使用由该软件包提供的完整类堆栈
我建议使用 http()
函数,以保持软件包的目的:简洁。
使用 http()
// GET (get from uri) /** @var string $response */ $response = http('https://httpbin.org/get'); // POST (post data to uri) /** @var \Rokde\HttpClient\Response $response */ $response = http()->post(['data' => 'value'], 'https://httpbin.org/post');
使用类版本
$client = new \Rokde\HttpClient\Client(); $request = new \Rokde\HttpClient\Request('https://httpbin.org/get', 'GET', [ 'accept' => 'application/json', 'x-verify-test' => 'true', ]); $response = $client->send($request); if ($response->isOk()) { $resultString = $response->content(); }
更多使用示例可以在该软件包的 /tests
文件夹中找到。
测试
使用以下命令运行测试
composer test