如何使用Term :: ProgressBar和LWP :: UserAgent的post方法创建进度条?

时间:2010-05-18 18:11:00

标签: perl post lwp

#!/usr/bin/perl

use LWP::UserAgent;
use HTTP::Request::Common;
use HTML::TreeBuilder;
use Cwd 'realpath';

use warnings;
use strict;

my $ua = LWP::UserAgent->new();

my $response = $ua->request(
                POST 'http://mydomain.com/upload.php',
                'Content-Type' => 'multipart/form-data',
                'Content' => [ 'fileup' => [realpath(shift)] ],
              );

my $tree = HTML::TreeBuilder->new_from_content($response->decoded_content);

my $image = $tree->look_down('_tag','a',sub { $_[0]->{href} =~ /http:\/\/images.mydomain.com\/images\/[^\?]/ if $_[0]->{href}})->{href};
print "\n".$image."\n\n";

如何为显示上传的脚本创建进度条? :content_cb让你在上传图像后为响应创建进度条,那么如何进行上传呢?

1 个答案:

答案 0 :(得分:0)

这不能解答您的初始问题,但也许您可以使用内置进度条:

$ua->show_progress
$ua->show_progress( $boolean )
    Get/set a value indicating whether a progress bar should be displayed on on the
    terminal as requests are processed. The default is FALSE.

(来自LWP :: UserAgent POD)