如果您仅在浏览器中输入网址,则可以看到两者都起作用,即使没有javascript也可以使用cdon,它们是否以某种方式阻止了cURL?
我正在尝试制作一个刮刀来在线上使合法电影受益,这将使它们受益匪浅,在一般的恕我直言中,愚蠢地阻止了刮刀.尽管我不确定这是怎么回事!可能只是某个地方的错误.
// Works
get_file1('http://sfanytime.com/sv-SE/Sokresultat/?field=all&q=The+Matrix', '/', 'sfanytime.html');
// Saves a blank 0 KB file
get_file1('http://downloads.cdon.com/index.phtml?action=search&search_terms=The+Matrix', '/', 'cdon.html');
function get_file1($file, $local_path, $newfilename) {
$out = fopen($newfilename, 'wb');
if ($out === FALSE) {
return false;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$error = curl_error($ch);
if (strlen($error) > 0) {
echo "
Error is : ". $error;
return false;
}
curl_close($ch);
return true;
}
解决方法:
你应该换线
curl_setopt($ch, CURLOPT_FAILONERROR, true);
…至…
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
CURLOPT_FAILONERROR将导致“无提示失败”-从您所说的开始,这不是您想要的.我已经用CURLOPT_FOLLOWLOCATION替换了它,因为当我访问第二个URL时,我被重定向到“选择您的国家”类型的页面,该页面的正文为空-这就是为什么您得到一个空文件的原因.
这样,您的代码就没有问题,而只是处理第二个URL响应的方式上的问题.您不会看到错误,因为从技术上讲,没有一个错误.
标签:curl,php
来源: https://codeday.me/bug/20191202/2085296.html