Download the PHP package berlioz/http-client without Composer
On this page you can find all versions of the php package berlioz/http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download berlioz/http-client
More information about berlioz/http-client
Files in berlioz/http-client
Package http-client
Short Description Berlioz HTTP Client is a PHP library to request HTTP server with continuous navigation, including cookies, sessions...
License MIT
Homepage https://getberlioz.com
Informations about the package http-client
Berlioz HTTP Client
Berlioz HTTP Client is a PHP library to request HTTP server with continuous navigation, including cookies, sessions... Implements PSR-18 (HTTP Client), PSR-7 (HTTP message interfaces) and PSR-17 (HTTP Factories) standards.
Installation
Composer
You can install Berlioz HTTP Client with Composer, it's the recommended installation.
Dependencies
- PHP ^8.0
- PHP libraries:
- curl
- mbstring
- zlib
- Packages:
- berlioz/http-message
- elgigi/har-parser
- psr/http-client
- psr/log
Usage
Requests
With RequestInterface
You can construct your own request object whose implements RequestInterface
interface (PSR-7).
Get/Post/Patch/Put/Delete/Options/Head/Connect/Trace
Methods are available to do request with defined HTTP method:
Client::get(...)
Client::post(...)
Client::patch(...)
Client::put(...)
Client::delete(...)
Client::options(...)
Client::head(...)
Client::connect(...)
Client::trace(...)
Example with Client::get()
:
You also can pass HTTP method in argument to Client::request(...)
method:
Each method accept an array of options with $options
argument.
List of options:
- baseUri (string): Base of URI if not given in requests
- followLocation (bool): Follow redirections (default: true)
- followLocationLimit (int): Limit location to follow
- sleepTime (int): Sleep time between requests (ms) (default: 0)
- logFile (string): Log file name (only file name, not path)
- exceptions (bool): Throw exceptions on error (default: true)
- cookies (null|false|CookiesManager): NULL: to use default cookie manager; FALSE: to not use cookies; a CookieManager object to use
- callback (callable): Callback after each request
- headers (array): Default headers
Options passed in argument replace default options of client.
Session
The session is accessible with method Client::getSession()
.
History
The browsing history is saved in the session. If you serialize the object Session
, the history is preserve.
The method Session::getHistory()
returns an History
object:
Cookies
A cookie manager is available to manage cookies of session and between requests. The manager is available
with Session::getCookies()
method.
If you serialize the object Session
, the cookies are preserves.
HAR file
HAR file of session is accessible with method Session::getHar()
.
If you serialize the object Session
, the HAR is preserved.
Refers to the documentation of elgigi/har-parser library: https://github.com/ElGigi/HarParser
Adapters
Usage
Default adapter used by library is CurlAdapter
(if CURL extension is installed), else the StreamAdapter
is used.
You can specify adapters to the client constructor, with argument adapter
:
The first specified adapter is the default adapter.
If you want force an adapter for a request, you can pass is name in the request options:
List
List of adapters:
- curl:
Berlioz\Http\Client\Adapter\CurlAdapter
- stream:
Berlioz\Http\Client\Adapter\StreamAdapter
- har:
Berlioz\Http\Client\Adapter\HarAdapter
HarAdapter
The HarAdapter
is specially made to simulate a navigation, coming from a desktop browser for example.
It's very useful for test units. You only need to store your cleaned HAR file into your repository to launch tests with simulated HTTP dialogs.
Har adapter accept an option strict
(default: false
) to force the way of navigation.
Create an adapter
You can create an adapter for your project.
You must implement the interface Berlioz\Http\Client\Adapter\AdapterInterface
.
All versions of http-client with dependencies
ext-mbstring Version *
ext-zlib Version *
berlioz/http-message Version ^2.1
elgigi/har-parser Version ^1.0
psr/http-client Version ^1.0
psr/log Version ^1.0 || ^2.0 || ^3.0