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: Re: [hostage] Watching UserAgent progress: Edit Log


Jan 24, 2012, 9:53 AM

Views: 1572
Re: [hostage] Watching UserAgent progress

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)

Edit Log:
Post edited by wickedxter (User) 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