如何使用 Term::ProgressBar 和 LWP::UserAgent 的 post 方法制作进度条?
#!/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 让您在上传图像后为响应创建进度条,那么我该如何为上传本身做呢?
#!/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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不能回答您最初的问题,但也许您可以使用内置进度条:(
来自 LWP::UserAgent POD)
This doesn't answer your initial question, but maybe you can use the builtin progress bar instead:
(from LWP::UserAgent POD)