1

嗨,我希望能够做到以下几点:

<?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");” 这也是因为数据被压缩了!

4

2 回答 2

0

弄清楚他们如何检查是否提供 HTML 页面或 torrent 文件。我的猜测是HTTP_REFERER。恶搞它。

于 2012-05-10T19:19:59.127 回答
0

如果$_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;
于 2012-07-10T07:13:39.037 回答