sunrise / http-client-curl
基于PSR-18的简单PHP 7.1+ cURL HTTP客户端
v1.4.6
2022-04-19 19:08 UTC
Requires
- php: ^7.1|^8.0
- ext-curl: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: 7.5.20|9.5.0
- sunrise/coding-standard: 1.0.0
- sunrise/http-factory: 2.0.0
Provides
- dev-master
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/phpunit-phpunit-9.x
- dev-renovate/psr-http-message-2.x
- dev-renovate/sunrise-http-factory-2.x
- dev-release/v1.4.5
- dev-release/v1.4.4
- dev-release/v1.4.3
- dev-release/v1.4.1
- dev-release/v1.4.0
- dev-release/v1.3.0
This package is auto-updated.
Last update: 2024-09-19 13:17:43 UTC
README
安装
composer require sunrise/http-client-curl
快速入门
composer require sunrise/http-factory
use Sunrise\Http\Client\Curl\Client; use Sunrise\Http\Factory\RequestFactory; use Sunrise\Http\Factory\ResponseFactory; $client = new Client(new ResponseFactory()); $request = (new RequestFactory)->createRequest('GET', 'https://php.ac.cn/'); $response = $client->sendRequest($request); echo $response->getStatusCode(), PHP_EOL;
cURL选项
$client = new Client(new ResponseFactory(), [ \CURLOPT_AUTOREFERER => true, \CURLOPT_FOLLOWLOCATION => true, ]);
多个请求的并行执行
$requests = [ (new RequestFactory)->createRequest('GET', 'https://php.ac.cn/'), (new RequestFactory)->createRequest('GET', 'https://php.ac.cn/'), ]; $client = new Client(new ResponseFactory()); $responses = $client->sendRequests(...$request); foreach ($responses as $i => $response) { // note that you can get the response's request by its index... echo sprintf('%s => %d', $requests[$i]->getUri(), $response->getStatusCode()), PHP_EOL; }
测试运行
composer test