1. Go to this page and download the library: Download shewa12/wp-http-client 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/ */
shewa12 / wp-http-client example snippets
use Shewa\WP_HTTP_Client\HTTPClient;
// Instantiate the HTTPClient class
$http_client = new HTTPClient();
$url = 'https://api.example.com/data';
$response = $http_client->request( 'get', $url );
if ( ! is_wp_error( $response ) ) {
// Process the response data
print_r( $response );
} else {
// Handle the error
echo 'Error: ' . $response->get_error_message();
}
$url = 'https://api.example.com/data';
$data = ['name' => 'John'];
$response = $http_client->request( 'post', $url, $data );
if ( ! is_wp_error( $response ) ) {
// Process the response data
print_r( $response );
} else {
// Handle the error
echo 'Error: ' . $response->get_error_message();
}