cUrl无法访问文件,但浏览器可以访问

时间:2017-02-28 13:55:00

标签: php curl

我想通过cUrl获取文件内容(没有file_get_contents函数)但是我无法用cUrl打开它

我的链接是here

我使用requestb.in测试了我的托管,结果为here

$header = array();
$header[] = 'Accept-Encoding: gzip';
$header[] = 'Connection: close';
$header[] = 'Host: panel.1n3k.com';
$header[] = 'User-Agent: runscope-radar/2.0';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);

我尝试使用代理CURLOPT_USERAGENT和我的浏览器代理。

CURLOPT_REFERERCURLOPT_ENCODINGCURLOPT_AUTOREFERER

一个接一个但没有人可以帮助我...

这怎么可能?

1 个答案:

答案 0 :(得分:0)

尝试使用此功能查看链接图像内容

<?php 
header("Content-Type: image/jpeg");

$url = 'http://panel.1n3k.com/6512bd43d9caa6e02c990b0a82652dca/api/media/4/logo/831710_1464331440.png';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
curl_close($ch) ;
echo $res;
?>