CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Watching UserAgent progress

 



hostage
Novice

Jan 23, 2012, 4:04 AM

Post #1 of 2 (761 views)
Watching UserAgent progress Can't Post

i want to download a file so i use the LWP::UserAgent module how can i understand the downloaded size of the url i entered for download while downloading is in progress ?

thanks alot - hostage


wickedxter
User

Jan 24, 2012, 9:53 AM

Post #2 of 2 (736 views)
Re: [hostage] Watching UserAgent progress [In reply to] Can't Post

 
from lwp::useragent module (its alomost at the bottom of the page.)

Quote
response_data => sub { my($response, $ua, $h, $data) = @_; ... }

This handler is called for each chunk of data received for the response. The handler might croak to abort the request.

This handler needs to return a TRUE value to be called again for subsequent chunks for the same request.
response_done => sub { my($response, $ua, $h) = @_; ... }

The handler is called after the response has been fully received, but before any redirect handling is attempted. The handler can be used to extract information or modify the response.


http://search.cpan.org/~gaas/libwww-perl-6.03/lib/LWP/UserAgent.pm




found this in the lwpcookbook



Code
  use LWP::UserAgent; 
$ua = LWP::UserAgent->new;
$URL = 'ftp://ftp.unit.no/pub/rfc/rfc-index.txt';

my $expected_length;
my $bytes_received = 0;
my $res =
$ua->request(HTTP::Request->new(GET => $URL),
sub {
my($chunk, $res) = @_;
$bytes_received += length($chunk);
unless (defined $expected_length) {
$expected_length = $res->content_length || 0;
}
if ($expected_length) {
printf STDERR "%d%% - ",
100 * $bytes_received / $expected_length;
}
print STDERR "$bytes_received bytes received\n";

# XXX Should really do something with the chunk itself
# print $chunk;
});
print $res->status_line, "\n";



(This post was edited by wickedxter on Jan 24, 2012, 9:56 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives