davidlienhard/httpclient
🐘 php library to send http requests
Setup
You can install through composer
with:
composer require davidlienhard/httpclient
Note: davidlienhard/httpclient requires PHP 8.0
Examples
Simple Example
<?php declare(strict_types=1);
use DavidLienhard\HttpClient\Client;
$http = new Client;
$response = $http->get("https://test.com/");
echo $response->getHttpCode() === 200
? "request was successful"
: "request failed";
Do not verify SSL Cert
<?php declare(strict_types=1);
use DavidLienhard\HttpClient\Client;
use DavidLienhard\HttpClient\Request;
$request = (new Request)->verifySslPeer(false);
$http = new Client($request);
$response = $http->get("https://test.com/");
echo $response->getHttpCode() === 200
? "request was successful"
: "request failed";
Add Cookies
<?php declare(strict_types=1);
use DavidLienhard\HttpClient\Client;
use DavidLienhard\HttpClient\Cookie;
use DavidLienhard\HttpClient\CookieJar;
use DavidLienhard\HttpClient\Request;
$cookiejar = new CookieJar(
new Cookie("name1", "value1"),
new Cookie("name2", "value2")
);
$http = new Client(cookiejar: $cookiejar);
$response = $http->get("https://test.com/");
echo $response->getHttpCode() === 200
? "request was successful"
: "request failed";
License
The MIT License (MIT). Please see LICENSE for more information.