纯Perl从另一个HTTP资源流式传输的最简单方法是什么?
在Perl中从另一个HTTP资源流式传输的最简单的方法是什么(没有打开shell来卷曲和从stdin读取)?我在这里假设我正在读取的HTTP资源是一个潜在的无限流(或者只是真的,非常长)
解决方法
HTTP::Lite的请求方法允许您指定回调.
但是,查看源代码,子请求中似乎存在一个错误,它似乎忽略了传递的回调.使用set_callback似乎更安全: #!/usr/bin/perl use strict; use warnings; use HTTP::Lite; my $http = HTTP::Lite->new; $http->set_callback(&;process_http_stream); $http->http11_mode(1); $http->request('http://www.example.com/'); sub process_http_stream { my ($self,$phase,$dataref,$cbargs) = @_; warn $phase,"n"; return; } 输出: C:Temp> ht connect content-length done-headers content content-done data done 看起来传递给请求方法的回调被区别对待: #!/usr/bin/perl use strict; use warnings; use HTTP::Lite; my $http = HTTP::Lite->new; $http->http11_mode(1); my $count = 0; $http->request('http://www.example.com/',&;process_http_stream,$count,); sub process_http_stream { my ($self,$data,$times) = @_; ++$$times; print "$$times====n$$datan===n"; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |