mercredi 25 avril 2018

PHP CURL returning 301 Location

My curl php code is returning 301 and i can't print out what the curl returned. this is my code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://subdomain.thinkific.com/api/public/v1/users/3418346");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

$headers = array();
$headers[] = "X-Auth-Api-Key: myapikey";
$headers[] = "X-Auth-Subdomain: subdomain";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
var_dump($result);

Here is what it returned:

string(142) "301{"Location"=>"https:subdomain.thinkific.com/api/public/v1/users/3418346", "Cache-Control"=>"no-cache"}#" 

i have tried json_decode the result to print it, still the same. as well as i also tried those:

curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_NOBODY, 1); //this one returned string(0) without 301

I need to know if the error is from my server or it has something to do with my code. ( i did not share api key and subdomain for privacy sorry).




Aucun commentaire:

Enregistrer un commentaire