PHP
PHP
Simple GET using REST
See more REST Examples
Demonstrates how to do a simple HTTP GET request using REST.Chilkat PHP Downloads
<?php
use Chilkat2\Rest;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$rest = new Rest();
// Connect to the REST server.
$bTls = true;
$port = 443;
$bAutoReconnect = true;
$rest->Connect('my-store.com', $port, $bTls, $bAutoReconnect);
try {
$responseJson = $rest->FullRequestNoBody('GET', '/wp-json/wc/v1/products?consumer_key=YOUR_CONSUMER_KEY&consumer_secret=YOUR_CONSUMER_SECRET');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo $responseJson, "\n";
echo "----\n";
// We can alternatively do this:
$rest->ClearAllQueryParams();
$rest->AddQueryParam('consumer_key', 'YOUR_CONSUMER_KEY');
$rest->AddQueryParam('consumer_secret', 'YOUR_CONSUMER_SECRET');
try {
$responseJson = $rest->FullRequestNoBody('GET', '/wp-json/wc/v1/products');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo $responseJson, "\n";