Perl 如何下载“解码内容”`
***更新了带有恢复功能的代码***Perl 如何下载“解码内容”`,perl,download,lwp-useragent,resume-download,Perl,Download,Lwp Useragent,Resume Download,***更新了带有恢复功能的代码*** my $ua = LWP::UserAgent->new; $ua->credentials('$ip:80', 'Realm', 'username', 'password'); my $response = $ua->mirror($url,$newfile); if ($response->is_success) { print "Download Successfull.";
my $ua = LWP::UserAgent->new;
$ua->credentials('$ip:80', 'Realm', 'username', 'password');
my $response = $ua->mirror($url,$newfile);
if ($response->is_success) {
print "Download Successfull.";
}
else {
print "Error: " . $response->status_line;
}
my $ua = LWP::UserAgent->new;
$ua->credentials('$ip:80', 'Realm', 'username', 'password');
my $response = $ua->get($url);
if ($response->is_success) {
print "Retrieved " .length($response->decoded_content) .
" bytes of data.";
}
else {
print "Error: " . $response->status_line;
}
open my $fh, '>encoding(UTF-8)', $tmp;
print {$fh} $response->decoded_content;
close $fh;
if ( -e $tmp ) {
my $filesize = ( stat $tmp )[9];
my $origsize = $queue[$rec][1];
if ( $filesize < $origsize) {
print "Resuming download";
******************************************
code for resuming the partly downloaded file...
*******************************************
}
else {
print "File downloaded correctly\n";
}
}
*********旧代码******************
my $ua = LWP::UserAgent->new;
$ua->credentials('$ip:80', 'Realm', 'username', 'password');
my $response = $ua->mirror($url,$newfile);
if ($response->is_success) {
print "Download Successfull.";
}
else {
print "Error: " . $response->status_line;
}
my $ua = LWP::UserAgent->new;
$ua->credentials('$ip:80', 'Realm', 'username', 'password');
my $response = $ua->get($url);
if ($response->is_success) {
print "Retrieved " .length($response->decoded_content) .
" bytes of data.";
}
else {
print "Error: " . $response->status_line;
}
open my $fh, '>encoding(UTF-8)', $tmp;
print {$fh} $response->decoded_content;
close $fh;
if ( -e $tmp ) {
my $filesize = ( stat $tmp )[9];
my $origsize = $queue[$rec][1];
if ( $filesize < $origsize) {
print "Resuming download";
******************************************
code for resuming the partly downloaded file...
*******************************************
}
else {
print "File downloaded correctly\n";
}
}
my$ua=LWP::UserAgent->new;
$ua->凭证(“$ip:80”,“领域”,“用户名”,“密码”);
my$response=$ua->get($url);
如果($response->is\u success){
打印“已检索”。长度($response->decoded_content)。
“字节数据。”;
}
否则{
打印“错误:.$response->status\u行;
}
打开我的$fh,“>编码(UTF-8)”,$tmp;
打印{$fh}$response->解码的内容;
收盘价$fh;
如果(-e$tmp){
my$filesize=(stat$tmp)[9];
my$origsize=$queue[$rec][1];
如果($filesize<$origsize){
打印“恢复下载”;
******************************************
用于恢复部分下载的文件的代码。。。
*******************************************
}
否则{
打印“正确下载的文件\n”;
}
}
由于我是perl的新手,我可以下载解码的内容
,尽管有些错误仍然存在。
需要恢复文件下载,如果我们有一个部分文件
这是我尝试过的代码,但我不知道从哪里开始,因此在这方面任何快速的想法都会有很大的帮助。请在这方面提供帮助。请参阅。文件报价:
此方法将获取由$url标识的文档,并将其存储在名为$filename的文件中
请参阅,它正确处理截断/部分下载的文件。也许您应该开始阅读一本书。阅读后,您可以根据stackoverflow的要求回答您的问题。Daxim感谢您的快速帮助。通过上述方式,我将文件下载到本地目录。但现在我必须从我的临时目录中恢复部分下载的文件。再次感谢Daxim,我忽略了你的回答。镜子()运转良好,符合我的要求。我添加了修改后的代码:)