davidlienhard/httpclient

🐘 php library to make http requests

1.0.4 2022-11-13 10:23 UTC

This package is auto-updated.

Last update: 2024-11-05 00:31:13 UTC


README

🐘 php library to send http requests

Latest Stable Version Source Code Software License Minimum PHP Version CI Status

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.