Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ddrv/php-http-client

simple HTTP client on PHP without cURL
https://github.com/ddrv/php-http-client

Last synced: about 2 months ago
JSON representation

simple HTTP client on PHP without cURL

Awesome Lists containing this project

README

        

[![Latest Stable Version](https://img.shields.io/packagist/v/ddrv/http-client.svg?style=flat-square)](https://packagist.org/packages/ddrv/http-client)
[![Total Downloads](https://img.shields.io/packagist/dt/ddrv/http-client.svg?style=flat-square)](https://packagist.org/packages/ddrv/http-client/stats)
[![License](https://img.shields.io/packagist/l/ddrv/http-client.svg?style=flat-square)](https://github.com/ddrv/php-http-client/blob/master/LICENSE)
[![PHP](https://img.shields.io/packagist/php-v/ddrv/http-client.svg?style=flat-square)](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
```