https://github.com/ddrv/php-http-client
simple HTTP client on PHP without cURL
https://github.com/ddrv/php-http-client
Last synced: 5 months ago
JSON representation
simple HTTP client on PHP without cURL
- Host: GitHub
- URL: https://github.com/ddrv/php-http-client
- Owner: ddrv
- License: mit
- Created: 2018-06-03T13:17:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-12-14T12:48:08.000Z (over 4 years ago)
- Last Synced: 2025-01-10T08:58:45.476Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://packagist.org/packages/ddrv/http-client)
[](https://packagist.org/packages/ddrv/http-client/stats)
[](https://github.com/ddrv/php-http-client/blob/master/LICENSE)
[](https://php.net)# ddrv/http-client
Simple HTTP client without cURL dependency. Required `allow_url_fopen` option in `php.ini` file.
```ini
; php.ini
allow_url_fopen = On
```# Install
Install this package, your favorite [psr-7 implementation](https://packagist.org/providers/psr/http-message-implementation) and your favorite [psr-17 implementation](https://packagist.org/providers/psr/http-factory-implementation).
```bash
composer require ddrv/http-client:^2.0
```# Using
```php
sendRequest($request);$code = $response->getStatusCode();
$phrase = $response->getReasonPhrase();
$headers = $response->getHeaders();
$someHeader = $response->getHeader('Content-Type');$body = $response->getBody()->__toString();
```# Configuration
```php
setFollowRedirects(0); // Set 0 follow redirects (disable).
$http->setTimeOut(10); // Set connection timeout 10 seconds$http->setProxy($proxy); // Set proxy
$http->setProxy(); // Unset proxy
```# SSL Authorization
```php
setSslAuth('host', 'ssl.crt', 'ssl.key'); // without password
$http->setSslAuth('host', 'ssl.crt', 'ssl.key', 'p@s$w0rd'); // with password
$http->unsetSslAuth('host'); // disable
```