我正在使用 PerlWWW::Mechanize
下载一个 MP3 文件,该文件以 400KB 的块(大约 20 秒)提供。
当我binmode
在文件句柄上保存数据时,在每个块到达时附加它,只有第一个块被正确播放;其余的不是。
当我不使用时binmode
,我无法播放整个文件——它会播放但听起来很有趣!
这是我的程序
use WWW::Mechanize;
$agent = WWW::Mechanize->new( cookie_jar => {} );
@links = ("http://thehost.com/chunk1","http://thehost.com/chunk2","http://thehost.com/chunk3");
foreach (@links){
$agent->get($_);
my $filename = 'test.mp3';
open(my $fh, '>>', $filename) or die "Could not open file '$filename' $!";
binmode $fh;
print $fh $agent->content;
close $fh;
}
我究竟做错了什么?
更新
这些是返回的 HTTP 标头。
Cache-Control: public
Connection: close
Date: Tue, 28 Oct 2014 18:38:37 GMT
Pragma:
Server: Apache
Content-Length: 409600
Content-Type: application/octet-stream
Expires: Sat, 24 Oct 2015 12:08:00 GMT
Access-Control-Allow-Origin: *
Client-Date: Tue, 28 Oct 2014 18:38:28 GMT
Client-Peer: **.**.***.***:80
Client-Response-Num: 1