0
$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;
7
  • do not know how, but I just copypaste your code and receive "Bad Request" response Commented May 6, 2014 at 13:15
  • Maybe because of curl_setopt($ch, CURLOPT_POST, 1); Makes your request a post, and it should be a get right? Commented May 6, 2014 at 13:16
  • first time i also get "Bad Request", but after try different curl and testing now i am only get empty result, while in browser you can see json response. Commented May 6, 2014 at 13:18
  • Could you try commenting the line I mentioned? i"m not sure but that's the main difference between the browser and the CURL request in this case Commented May 6, 2014 at 13:18
  • i removed curl_setopt($ch, CURLOPT_POST, 1); but still empty result. Commented May 6, 2014 at 13:20

2 Answers 2

2
$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

Sign up to request clarification or add additional context in comments.

2 Comments

this giving warning Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? its also not working
Warning: file_get_contents(itunes.apple.com/…): failed to open stream: No error in
0

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

2 Comments

unless 0 is auto casted to boolean (false), not sure but it worth a try
ok thanks, i used if(curl_error($ch)!=''){ echo "error: ".curl_error($ch); } but still empty response

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.