PHP Using curl with torcache



嗨,我希望能够执行以下操作:

<?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 可以获得实际的种子吗?目前$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");",这也是因为数据被gzip压缩了!

弄清楚他们如何检查是服务器HTML页面还是种子文件。我的猜测是HTTP_REFERER.欺骗它。

如果$_GET['tor']包含来自 torrentz.eu 站点的info_hash,这应该可以解决问题。

$ch = curl_init('http://torcache.net/torrent/'.strtoupper($_GET['tor']).'.torrent');                                                                      
curl_setopt($ch, CURLOPT_POSTFIELDS, null);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);                                                                 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-bittorrent','Referer: http://torcache.net/torrent/'.strtoupper($_GET['tor']).'.torrent')); 
curl_setopt($ch, CURLOPT_REFERER, 'http://torcache.net/torrent/'.strtoupper($_GET['tor']).'.torrent'); 
curl_setopt($ch, CURLOPT_ENCODING,"gzip");
$result = curl_exec($ch);
echo $result;

最新更新