1. Go to this page and download the library: Download sirmonti/shttp 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/ */
// Disable certificate validation
SHTTP::verifCERT=false;
// Set exception level to 2
SHTTP::setExceptionLevel(2);
// All subsequent requests will operate with this parameters
$resp=SHTTP::get('https://www.examples.com/');
// Exception level 2 (exception on network or HTTP errors)
SHTTP::setExceptionLeve(2);
// Certificate validation disabled (Will accept any certificate)
SHTTP::verifCERT=false;
$data=[
'field1'=>'Data to send in field1',
'field2'=>'Data to send in field2'
];
// Execute a POST request sending the content of the $data variable
$resp=SHTTP::post('https://www.example.com/sendpoint',$data);
// Default exception level is 1, which means exceptions will be fired
// only on network errors
$data=[
'field1'=>'Data to send in field1',
'field2'=>'Data to send in field2'
];
$resp=SHTTP::postJSON('https://www.example.com/jsonentrypoint',$data);
// Create the authentication header
$headers=[
'Authorization: Bearer AuthenticationToken'
];
// Configure the default headers to send
SHTTP::setExtraHeaders($headers);
$data=[
'field1'=>'Data to send in field1',
'field2'=>'Data to send in field2'
];
$resp=SHTTP::post('https://www.example.com/sendpoint',$data);
$headers=[
'Authorization: Bearer AuthenticationToken'
];
// This header will be used by all subsequent requests
SHTTP::setExtraHeaders($headers);
$data=[
'field1'=>'Data to send in field1',
'field2'=>'Data to send in field2'
];
// Add an extra header to this request
$resp=SHTTP::post('https://www.example.com/sendpoint',$data,['X-Extra-Header: Data']);
$headers=[
'Authorization: Bearer AuthenticationToken',
'User-Agent: MyOwnUserAgent/1.0'
];
SHTTP::setExtraHeaders($headers);
$data=[
'field1'=>'Data to send in field1',
'field2'=>'Data to send in field2'
];
$resp=SHTTP::post('https://www.example.com/sendpoint',$data);
$headers=[
'Authorization: Bearer AuthenticationToken',
'User-Agent: MyOwnUserAgent/1.0'
];
SHTTP::setExtraHeaders($headers);
$data=[
'field1'=>'Data to send in field1',
'field2'=>'Data to send in field2'
];
// Example PUT with body in JSON format
$resp=SHTTP::putJSON('https://www.example.com/sendpoint',$data);