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



wickedxter
User

Jan 24, 2012, 9:53 AM


Views: 747
Re: [hostage] Watching UserAgent progress

 
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)


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