[英]How do I make a progress bar using Term::ProgressBar with LWP::UserAgent's post method?
#!/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";
How do I create a progress bar for this script showing the upload? 如何为此显示上传的脚本创建进度条? :content_cb let's you create progress bars for the response after the image is uploaded, so how do I do it for the upload itself? :content_cb让我们在上传图片后为响应创建进度条,那么如何为上传本身做呢?
This doesn't answer your initial question, but maybe you can use the builtin progress bar instead: 这不能回答您最初的问题,但是也许您可以使用内置的进度条来代替:
$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.
(from LWP::UserAgent POD) (来自LWP :: UserAgent POD)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.