1. Go to this page and download the library: Download pdeans/http library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pdeans / http example snippets
use pdeans\Http\Client;
$client = new Client();
// With options
$client = new Client([
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => true,
]);
// GET request with header
$response = $client->get('https://example.com/1', ['custom-header' => 'header/value']);
// GET request without header
$response = $client->get('https://example.com/2');
// HEAD request
$response = $client->head('https://example.com/2');
// TRACE request
$response = $client->trace('https://example.com/2');
$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Basic ' . base64_encode('username:password'),
];
$data = json_encode(['json' => 'json data']);
// POST request with headers and request body
$response = $client->post('https://example.com/4', $headers, $data);
// PUT request
$response = $client->put('https://example.com/4', $headers, $data);
// PATCH request
$response = $client->patch('https://example.com/4', $headers, $data);
// OPTIONS request
$response = $client->options('https://example.com/4', $headers, $data);
// DELETE request
$response = $client->delete('https://example.com/4', $headers, $data);
use pdeans\Http\Factories\RequestFactory;
$request = (new RequestFactory())->createRequest('GET', 'https://example.com/1');
$response = $client->sendRequest($request);