2
#!/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 画像がアップロードされた後、応答用のプログレス バーを作成しましょう。

4

1 に答える 1

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 から)

于 2010-05-18T18:20:41.993 に答える