Frankly, I don't see much of a problem with LWP, simply use the
content method and not
as_string.
The piece of code belows downloads a file and compares it with itself using the SHA algorithm in order to prove the download was correct. I tested it with a number of binary files that were available on my Windows box and always worked right.
use strict;
use LWP::UserAgent;
use Digest::SHA1;
my $srcfile = "c:/...../cab/WBCust.CAB";
my $tempdl = "temp.tmp";
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => 'http://127.0.0.1/...../cab/WBCust
+.CAB');
my $r = $ua->request($req)->content;
open F, ">$tempdl" or die "$! $tempdl";
binmode F;
print F $r;
close F;
computeSHA( $srcfile );
computeSHA( $tempdl );
unlink $tempdl;
exit;
sub computeSHA() {
my ($srcfile) = @_;
my $sh_pre = Digest::SHA1->new;
open S1, $srcfile or die "$! $srcfile";
$sh_pre->addfile(*S1);
close S1;
print "$srcfile:\n " . $sh_pre->hexdigest . "\n";
}
The result is something like:
c:/...../cab/WBCust.CAB:
3816f34e861b6268c716b9f06091dee0d580f2cb
temp.tmp:
3816f34e861b6268c716b9f06091dee0d580f2cb