$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;
-
do not know how, but I just copypaste your code and receive "Bad Request" responsepomaxa– pomaxa2014-05-06 13:15:33 +00:00Commented 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?Mathijs Segers– Mathijs Segers2014-05-06 13:16:54 +00:00Commented 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.Sunil Dabhi– Sunil Dabhi2014-05-06 13:18:10 +00:00Commented 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 caseMathijs Segers– Mathijs Segers2014-05-06 13:18:56 +00:00Commented May 6, 2014 at 13:18
-
i removed curl_setopt($ch, CURLOPT_POST, 1); but still empty result.Sunil Dabhi– Sunil Dabhi2014-05-06 13:20:14 +00:00Commented May 6, 2014 at 13:20
|
Show 2 more comments
2 Answers
$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
2 Comments
Sunil Dabhi
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
Sunil Dabhi
Warning: file_get_contents(itunes.apple.com/…): failed to open stream: No error in
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);
}
2 Comments
Yazan
unless 0 is auto casted to boolean (false), not sure but it worth a try
Sunil Dabhi
ok thanks, i used if(curl_error($ch)!=''){ echo "error: ".curl_error($ch); } but still empty response