嗨,我希望能够做到以下几点:
<?php
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$data = get_data('https://torcache.net/torrent/7975CDEEDCEC6092729DAEAE302CB9BD7D633B0B.torrent');
?>
然而,似乎 torcache 正在返回一个 html 页面,然后种子在几秒钟后被切断,curl 是否有办法获得实际的 torrent?一分钟 $data 只包含 html 页面 torcache 返回?
尝试将引用设置为: curl_setopt($ch, CURLOPT_REFERER, 'https://torcache.net/torrent/7975CDEEDCEC6092729DAEAE302CB9BD7D633B0B.torrent');
但不工作,我得到这个回应:
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx/1.2.0</center>
</body>
</html>
谢谢
解决了:
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_REFERER, 'https://torcache.net/');
curl_setopt($ch,CURLOPT_ENCODING,"gzip");
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
添加“curl_setopt($ch,CURLOPT_ENCODING,"gzip");” 这也是因为数据被压缩了!