【问题标题】:PHP Using curl with torcachePHP 使用 curl 和 torcache
【发布时间】:2012-05-10 19:13:46
【问题描述】:

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

<?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 只包含 torcache 返回的 html 页面?

尝试将referer设置为: 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");"这也是因为数据被压缩了!

【问题讨论】:

    标签: php html curl


    【解决方案1】:

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

    【讨论】:

    • 里面有一些 javascript,不会提供下载服务吗?
    • 看起来不像。使用 Chrome 检查器或 Firebug 打开它,然后转到 Network / Net 选项卡。网址是一样的。
    • 所以我唯一能看到的是 mime 类型不同?寻找如何欺骗这个但什么都看不到:(
    • 您不发送 Mime-Type .. 服务器为您设置。您是否尝试过设置 HTTP_REFERER 标头?
    • 是的,它不工作它只是发回一个“302 Found”不太确定我应该设置什么引用。 Atm 是: curl_setopt($ch, CURLOPT_REFERER, 'torcache.net/torrent/…);
    【解决方案2】:

    如果$_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;
    

    【讨论】:

    • 使用 $_GET 中的某些东西而不首先对其进行清理来执行 curl 请求,这看起来可能是一个安全问题,这次可能没那么严重,但这是一个坏习惯。
    • 谢谢,我确实使用类似的过程让它最终工作,回家后我会发布我的代码以供参考
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-06
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多