jlongino has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Error checking LWP::UserAgent
by blakem (Monsignor) on Oct 29, 2001 at 11:55 UTC
    From 'perldoc LWP':
    # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ($res->is_success) { print $res->content; } else { print "Bad luck this time\n"; }

    -Blake

      Thanks blakem. I checked out the docs on LWP::UserAgent and several nodes before posting but didn't think to look at just LWP.

      --Jim