免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: maybenot
打印 上一主题 下一主题

Mojo UserAgent 上传文件,进度问题 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2017-06-17 18:25 |只看该作者
本帖最后由 maybenot 于 2017-06-17 18:29 编辑

[size=1em][size=1em]use [color=black !important][size=1em]Mojo::UserAgent;

[size=1em]# Build a normal transaction
[size=1em]my $ua = Mojo::UserAgent->new;
[size=1em]my $tx = $ua->build_tx(GET => '[color=blue !important][size=1em]http://example.com');

[size=1em]# Prepare body
[size=1em]my $body = 'Hello World!';
[size=1em]$tx->req->headers->content_length(length $body);

[size=1em]# Start writing directly with a drain callback
[size=1em]my $drain;
[size=1em]$drain = sub {
[size=1em]  my $content = shift;
[size=1em]  my $chunk = substr $body, 0, 1, '';
[size=1em]  $drain = undef unless length $body;
[size=1em]  $content->write($chunk, $drain);
[size=1em]};
[size=1em]$tx->req->content->$drain;

[size=1em]# Process transaction
[size=1em]$tx = $ua->start($tx);

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP