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

In reply to Re: Download file over HTTP by l3nz
in thread Download file over HTTP by chaskins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.