[pm-h] LWP::UserAgent

Mark Allen mrallen1 at yahoo.com
Sun Feb 19 13:29:15 PST 2012


Depending on how new your LWP is you'll need LWP::protocol::https too. It's decoupled as of version 6.

Also can check out lwp-request script that comes with LWP. It's a nice example.

Sent from my iPhone

On Feb 19, 2012, at 3:25 PM, "G. Wade Johnson" <gwadej at anomaly.org> wrote:

> On Sun, 19 Feb 2012 14:51:57 -0600
> Mike Flannigan <mikeflan at att.net> wrote:
> 
>> 
>> I've got a question for you guys.  Maybe an
>> easy question.
>> 
>> I want to download the file '02251_new_1923-0059.zip'
>> from the website:
>> https://spatialdata.iu.edu/DOQQS/state/sanborn/public/tif/1923/
>> 
>> The script below works (I think), but it outputs the
>> file to STDout.  I haven't tried yet, but I gather if
>> I print this to a filehandle I will not get the binary
>> zip file, but a text file instead.
>> 
>> What is the proper way to download the file to a binary
>> zip file using LWP::UserAgent and the Crypt-SSLeay module
>> I just obtained from University of Winnipeg?
>> http://johnbokma.com/perl/https.html
>> 
>> 
>> 
>> Mike
>> 
>> 
>> 
>> use warnings;
>> use strict;
>> use LWP::UserAgent;
>> 
>> my $url = 
>> 'https://spatialdata.iu.edu/DOQQS/state/sanborn/public/tif/1923/02251_new_1923-0059.zip';
>> 
>> my $ua = LWP::UserAgent->new;
>> my $response = $ua->get( $url );
>> 
>> $response->is_success or die "Failed to GET '$url': ", 
>> $response->status_line;
>> 
>> print $response->as_string;
> 
> LWP::UserAgent has a mirror() method that downloads directly to a file.
> 
> G. Wade
> -- 
> All things are possible, given enough time and caffeine.
>                                                     -- Danny Hoover
> _______________________________________________
> Houston mailing list
> Houston at pm.org
> http://mail.pm.org/mailman/listinfo/houston
> Website: http://houston.pm.org/


More information about the Houston mailing list