由於服務器正在使用gzip encription,因此在下載時出現錯誤洪流。使用php下載洪流形式torcache.com?
<?
$path_parts = pathinfo("http://torcache.com/torrent/56A250DC4CD64F6C304631897F1108D413FE76C7.torrent");
$name= $path_parts['basename'];
$d="torrent/".$name;
if(!copy($f,$d))
{
echo "not copied";
}
else
{
echo "copied";
}
?>
然後我用這則還其結果是無效的洪流
<?php
/* Tutorial by AwesomePHP.com -> www.AwesomePHP.com */
/* Function: download remote file */
/* Parameters: $url -> to download | $dir -> where to store file |
$file_name -> store file as this name - if null, use default*/
/* $path_parts = pathinfo("http://torcache.com/torrent/56A250DC4CD64F6C304631897F1108D413FE76C7.torrent");
$name= $path_parts['basename'];
$d="torrent/".$name; */
$f="http://torcache.com/torrent/56A250DC4CD64F6C304631897F1108D413FE76C7.torrent";
downloadRemoteFile($f,"torrent/",$file_name = NULL);
function downloadRemoteFile($url,$dir,$file_name = NULL){
if($file_name == NULL){ $file_name = basename($url);}
$url_stuff = parse_url($url);
$port = isset($url_stuff['port']) ? $url_stuff['port'] : 80;
$fp = fsockopen($url_stuff['host'], $port);
if(!$fp){ return false;}
$query = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n";
$query .= 'Host: ' . $url_stuff['host'];
$query .= "\n\n";
fwrite($fp, $query);
while ($tmp = fread($fp, 8192)) {
$buffer .= $tmp;
}
preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts);
$file = substr($buffer, - $parts[1]);
$file_binary=($file);
if($file_name == NULL){
$temp = explode(".",$url);
$file_name = $temp[count($temp)-1];
}
$file_open = fopen($dir . "/" . $file_name,'w');
if(!$file_open){ return false;}
fwrite($file_open,$file_binary);
fclose($file_open);
return true;
}
?>
蟒蛇
import urllib2, httplib
httplib.HTTPConnection.debuglevel = 1
request = urllib2.Request('http://torcache.com/torrent/4F78CA71DD8C308F18426F845AFBFF4481633B11.torrent')
request.add_header('Accept-encoding', 'gzip')
opener = urllib2.build_opener()
f = opener.open(request)
compresseddata = f.read()
import StringIO
compressedstream = StringIO.StringIO(compresseddata)
import gzip
gzipper = gzip.GzipFile(fileobj=compressedstream)
data = gzipper.read()
print data
filename = "633B11.torrent"
FILE = open(filename,"w")
FILE.write(data)
然後我用python的室內用gzip壓縮還是我得到能無效的torrent文件anyboy幫助我解決php中的gzip問題,以使用gzip e從torrent緩存服務器下載torrent ncoding
Gzip不是*加密*算法,只是*壓縮*算法。 – deceze 2010-07-15 03:58:30