Cookie consent

AstroBin saves small pieces of text information (cookies) on your device in order to deliver better content and for statistical purposes. You can disable the usage of cookies by changing the settings of your browser. By browsing AstroBin without changing the browser settings, you grant us permission to store that information on your device.

I agree

Astrobin API return 301

21 Apr, 2018 15:20

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 :

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

$url = '' . $apiKey .'&api_secret=' . $apiSecret .'&format=json';
$curl = curl_init();
$options = [
    CURLOPT_URL => $url,
       CURLOPT_HEADER => false,
       CURLOPT_TIMEOUT => 10,
       CURLOPT_HTTPGET => true,
curl_setopt_array($curl, $options);

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

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 ( is not very helpfull :/ but as is see, mu URL is correct.

Thank you very much
Edited 21 Apr, 2018 15:22
21 Apr, 2018 22:10
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.