PHP code example of rpurinton / https

1. Go to this page and download the library: Download rpurinton/https 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/ */

    

rpurinton / https example snippets




Purinton\HTTPS\HTTPSRequest;

// Define the options for the request
$options = [
    'url' => 'https://raw.githubusercontent.com/rpurinton/https/master/example.json',
    'method' => 'GET',
    'headers' => [
        'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' .
            'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36',
    ],
    'body' => '',
];

// Return the response as a string
$response_string = HTTPSRequest::fetch($options);
echo "Response as String: $response_string\n";

$response_array = json_decode($response_string, true);
echo "Response as Array: " . print_r($response_array, true) . "\n";

$response_object = json_decode($response_string);
echo "Response as Object: " . print_r($response_object, true) . "\n";