Sunil Dabhi
Sunil Dabhi

Reputation: 99

php - curl empty response while browser display json output

$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://itunes.apple.com/search?term=Clean%20Bandit%20-%20Rather%20Be&entity=song&limit=10&lang=fr_fr');
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    if(curl_errno($ch))
        echo 'Curl error: '.curl_error($ch);
    $CurResult = curl_exec($ch);
    curl_close($ch);

    echo 'Result:'.$CurResult;

Upvotes: 0

Views: 1100

Answers (2)

Prasad V S
Prasad V S

Reputation: 362

$url = 'https://itunes.apple.com/search?term=Clean%20Bandit%20-%20Rather%20Be&entity=song&limit=10&lang=fr_fr';
$content = file_get_contents($url);
print_r($content);

Use this code to get the response curl is not needed in this case

Upvotes: 2

Yazan
Yazan

Reputation: 6082

from php manual

curl_errno()

does not return true or false, it returns error number 0, if no errors. so you either change the condition to

if(curl_errno($ch)!=0)

or use curl_error()

if(curl_error($ch)!=''){
    echo "error: ".curl_error($ch);
}

https://www.php.net/manual/en/function.curl-errno.php

Upvotes: 0

Related Questions