$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;
答案 0 :(得分: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);
使用此代码在这种情况下不需要响应curl
答案 1 :(得分:0)
来自php手册
curl_errno()
不返回true或false,如果没有错误,则返回错误号0。 所以你要么把条件改为
if(curl_errno($ch)!=0)
或使用curl_error()
if(curl_error($ch)!=''){
echo "error: ".curl_error($ch);
}