Re: $ua->sinple_request($request)

Marc Langheinrich (marclang@cs.washington.edu)
Fri, 26 Mar 1999 09:47:48 +0900


On Thu, Mar 25, 1999 at 10:01:59AM +0100, Ibon Aizpurua wrote:
> $response=$ua->sinple_request($request,'file_to_examine',size);
that won't work. You can only use the size parameter if you're using
callbacks. The "lwpcook" manpage gives an example on how you would read
large files: (you might want to use simple_request instead of request)


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

    my $expected_length;
    my $bytes_received = 0;
    $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;
     });


marc
--
Marc Langheinrich
marclang@cs.washington.edu