1. Go to this page and download the library: Download tg111/php-request 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/ */
tg111 / php-request example snippets
use PhpRequest\PhpRequest;
// Simple GET request
$response = PhpRequest::get('https://httpbin.org/get');
echo $response->text();
// GET with parameters
$response = PhpRequest::get('https://httpbin.org/get', [
'key1' => 'value1',
'key2' => 'value2'
]);
// POST with data
$response = PhpRequest::post('https://httpbin.org/post', [
'username' => 'user',
'password' => 'pass'
]);
// JSON POST
$response = PhpRequest::post('https://httpbin.org/post', [
'name' => 'John Doe',
'email' => '[email protected]'
], [
'headers' => ['Content-Type' => 'application/json']
]);
// Alternative syntax using global functions
$response = requests_get('https://httpbin.org/get');
$response = requests_post('https://httpbin.org/post', ['key' => 'value']);