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

发布于 2024-09-02 04:30:46 字数 758 浏览 4 评论 0原文

#!/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑忘罢 2024-09-09 04:30:46

这并不能回答您最初的问题,但也许您可以使用内置进度条:(

$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)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文