m3LLow has asked for the wisdom of the Perl Monks concerning the following question:

Back to the post: 182856 (It was really useful, thank you once more)

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";
But how to do this using POST method including submission of serveral variables?

Replies are listed 'Best First'.
Re: Using callback on the response for the POST method
by aersoy (Scribe) on Jul 18, 2002 at 21:28 UTC

    Hello,

    You can do it with an HTTP::Request object.

    my $req = HTTP::Request->new(POST => $URL); $req->content_type('application/x-www-form-urlencoded'); $req->content('param=value'); my $res = $ua->request($request, sub {...});

    You will find more information in the LWP manual (actually, that above code comes directly from that manual).

    I hope this helps.

    Update: Fixed a syntax error with the parentheses.

    --
    Alper Ersoy

      Thank you!
      A little correction to your code:

      my $res = $ua->request($request), sub {...}

      Should be:

      my $res = $ua->request($req, sub {...});

      Thank you once more! ;-)