Hi @correa
I was not able to get your code to work. From my understanding the file_get_contents
needs some server setup to GET HTTPS resources. You also probably need the Accept: application/json
header.
Still, I got it working with a code based on yours, but using cURL instead. Here it is:
$tKey = '---';
$headers = apache_request_headers();
$tToken = $headers['X-Snipcart-Requesttoken'];
$url = 'https://app.snipcart.com/api/requestvalidation/' . $tToken;
$auth = base64_encode($tKey . ':');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Basic ' . $auth
),
));
$response = curl_exec($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo $status_code;
if ($status_code == 200) {
echo 'OK';
} else {
echo 'FAIL';
}
// close cURL resource
curl_close($curl);
I hope this helps.
Thanks.