perf / http-client
Allows to execute HTTP queries.
2.0.0
2020-07-03 13:28 UTC
Requires
- php: >=7.4.0
- ext-curl: *
- perf/curl-client: ^2.0
Requires (Dev)
- ext-xdebug: *
- phing/phing: ^2.16
- phpmd/phpmd: ^2.8
- phpunit/phpunit: ^9.2
- squizlabs/php_codesniffer: ^3.5
README
Simple HTTP client using cURL internally.
Installation & Requirements
There are no dependencies on other libraries.
Install with Composer:
composer require perf/http-client
Usage
Simple GET request
<?php use perf\HttpClient\HttpClient; $httpClient = HttpClient::createDefault(); $request = $httpClient->createRequest(); $request ->methodGet() ->setUrl('http://localhost/index.html') ; $response = $httpClient->execute($request); $httpStatusCode = $response->getHttpStatusCode(); $content = $response->getBodyContent();
Simple POST request
<?php use perf\HttpClient\HttpClient; $httpClient = HttpClient::createDefault(); $request = $httpClient->createRequest(); $request ->methodPost( [ 'title' => 'test article', 'content' => 'article content ...', 'photo' => $httpClient->createFile('/path/to/file.jpg') ] ) ->setUrl('http://localhost/create-article.php') ; $response = $httpClient->execute($request); $httpStatusCode = $response->getHttpStatusCode(); $content = $response->getBodyContent();