Astrobin API return 301

HamHam
21 Apr, 2018 15:20
Hello,

I'm making a Webservices who request the Astrobin API REST, but however the endpoint i call, the response is always in HTML and with 301 HTTP code :

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.13.8</center>
</body>
</html>
I'm using cURL. Here's a simplified version of my code :

$url = 'http://astrobin.com/api/v1/imageoftheday/?limit=1&api_key=' . $apiKey .'&api_secret=' . $apiSecret .'&format=json';
$curl = curl_init();
$options = [
    CURLOPT_URL => $url,
       CURLOPT_RETURNTRANSFER => true,
       CURLOPT_HEADER => false,
       CURLOPT_TIMEOUT => 10,
    CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPGET => true,
];
curl_setopt_array($curl, $options);

if(!$resp = curl_exec($curl)) {
    twhrow new Exception("Problem " );
}
curl_close($curl);

if (is_string($resp)) {
       if (false === strpos($resp, '{', 0)) {
              // check if html
              if (false !== strpos($resp, '<html', 0)) {
                        throw new Exception(sprintf("Response from Astrobin is in HTML format :\n %s", $resp));
        }
        throw new Exception(sprintf("Response from Astrobin is not a JSON valid format :\n %s", $resp));
                    }
    $obj = json_decode($resp);
}
// etc …

The documentation (https://www.astrobin.com/help/api/) is not very helpfull :/ but as is see, mu URL is correct.

Thank you very much
Edited 21 Apr, 2018 15:22
siovene
21 Apr, 2018 22:10
Use HTTPS 😁
HamHam
22 Apr, 2018 12:13
Thank you, it works smile !!
I have adding "https", placed "www" too and adding "CURLOPT_SSL_VERIFYPEER => false" in my cURL options.

I thonk the doc might be updated and fix the URL smile
 
Register or login to create to post a reply.