This is the first time I've used the LWP::UserAgent module. I got it to work using code similar to the following (just the URL, file, login and password have been changed):
use strict; require LWP::UserAgent; my $ua = LWP::UserAgent->new(env_proxy => 1, keep_alive => 1, timeout +=> 30); print "'\$ua = LWP . . . ' Errors: $@\n"; my $req = HTTP::Request->new('GET', 'http://www.somewhere.org/csc/file +.exe'); print "'\$req = HTTP . . . ' Errors: $@\n"; $req->authorization_basic('login', 'password'); print "'\$req->author . . . ' Errors: $@\n"; my $resp = $ua->request($req, '/temp/file.exe'); print "'\$resp = \$ua-> . . . ' Errors: $@\n";
The problem is that before I got it to work, I typo'd a "/" onto the end of the HTTP request but no error messages were generated:
my $req = HTTP::Request->new('GET', 'http://www.somewhere.org/a/file.e +xe/');
The file was not downloaded either of course. So the question is what is the correct way to go about trouble shooting code like this. I want to incorporate it into a much more extensive application but I have to do more with the file after I download it.

I imagine that I could delete the file if it already existed, find in advance the size of the file to be downloaded and then verify afterwards that the file size is correct (if it exists). Is there a different module or approach that is more appropriate? Maybe reorganizing the process to an ftp'able account and using Net::Ftp?

Thanks in advance for any advice, or pointers in the right direction,

--Jim


In reply to Error checking LWP::UserAgent by jlongino

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.