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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Watching UserAgent progress



Jan 23, 2012, 4:04 AM

Post #1 of 2 (1598 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


Jan 24, 2012, 9:53 AM

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

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

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.

found this in the lwpcookbook

  use LWP::UserAgent; 
$ua = LWP::UserAgent->new;
$URL = '';

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