Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl LWP获取大文件下载_Perl_Lwp - Fatal编程技术网

Perl LWP获取大文件下载

Perl LWP获取大文件下载,perl,lwp,Perl,Lwp,我有一个文件下载的特殊情况。我需要对大文件进行分块下载,还需要在下载之前将参数传递给CGI脚本 它实际上是一个REST接口。我在互联网上搜索过,下载部分有很多东西,参数部分也有很多东西,但是当我把它们放在一起时,我会出错。还要注意的是,我以类似的方式发布了一篇文章,效果很好。这是我的代码片段: # $filename, $target, $url, $bs, etc. are all set... my $bytes_received = 0; open (FH, ">", "$file

我有一个文件下载的特殊情况。我需要对大文件进行分块下载,还需要在下载之前将参数传递给CGI脚本

它实际上是一个REST接口。我在互联网上搜索过,下载部分有很多东西,参数部分也有很多东西,但是当我把它们放在一起时,我会出错。还要注意的是,我以类似的方式发布了一篇文章,效果很好。这是我的代码片段:

# $filename, $target, $url, $bs, etc. are all set...
my $bytes_received = 0;

open (FH, ">", "$filename") or $logger->error("Couldn't open $filename for writing: $!" );
my $ua = LWP::UserAgent->new();
my $res = $ua->get(
    $url,
    ':content_cb' => \&callback,
    'Content' => {
    "api" => 'olfs',
    "cmd" => 'rfile',
    "target" => $target,
    "bs" => $bs});

    print $logger->info("$bytes_received bytes received");

sub callback{
    my($chunk, $res) = @_;
    $bytes_received += length($chunk);
    print FH $chunk;
}
以下是错误:

Not a SCALAR reference at /usr/local/share/perl5/HTTP/Message.pm line 163.
 at /usr/local/share/perl5/HTTP/Message.pm line 163
    HTTP::Message::add_content('HTTP::Request=HASH(0x1956a88)', 'HASH(0x7fdfda565e88)') called at /usr/local/share/perl5/HTTP/Request/Common.pm line 111
    HTTP::Request::Common::_simple_req(undef, undef) called at /usr/local/share/perl5/HTTP/Request/Common.pm line 20
    HTTP::Request::Common::GET('http://10.0.0.15:8084/cgi-bin/olss.cgi', 'Content', 'HASH(0x7fdfda565e88)') called at /usr/local/share/perl5/LWP/UserAgent.pm line 410
    LWP::UserAgent::get('LWP::UserAgent=HASH(0x191a220)', 'http://10.0.0.15:8084/cgi-bin/olss.cgi', ':content_cb', 'CODE(0x1845818)', 'Content', 'HASH(0x7fdfda565e88)') called at ./olfs_get.pl line 72
Debugged program terminated.  Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.
  DB<3> print oct("764")
500
  DB<4>
在/usr/local/share/perl5/HTTP/Message.pm第163行不是标量引用。
at/usr/local/share/perl5/HTTP/Message.pm第163行
在/usr/local/share/perl5/HTTP/Request/Common.pm第111行调用HTTP::Message::add_content('HTTP::Request=HASH(0x1956a88)','HASH(0x7FDA565E88')
HTTP::Request::Common::_simple_req(unde,unde)在/usr/local/share/perl5/HTTP/Request/Common.pm第20行调用
HTTP::Request::Common::GET('http://10.0.0.15:8084/cgi-在/usr/local/share/perl5/LWP/UserAgent.pm行410处调用bin/olss.cgi'、'Content'、'HASH(0x7fdfda565e88')
LWP::UserAgent::get('LWP::UserAgent=HASH(0x191a220)','http://10.0.0.15:8084/cgi-在/olfs_get.pl第72行调用bin/olss.cgi',':content_cb',CODE(0x1845818)',content',HASH(0x7fdfda565e88)'
已调试程序已终止。使用q退出,或使用R重新启动,
使用o inhibit_exit避免程序终止后停止,
h q、h R或h o以获取其他信息。
DB打印oct(“764”)
500
分贝
$ua->get($url)
$ua->get($url,$field\u name=>$value,…)

此方法将在给定的$url上发送GET请求。可以提供更多参数来初始化请求的头

没有
内容
标题这样的东西
->post
使用它来创建消息正文,它从不用于GET请求。如果要构建url,可以使用

$ua->post($url,$field\u name=>$value,$Content=>\%form)
$ua->post($url,$field\u name=>$value,$Content=>\@form)
$ua->post($url,$field\u name=>$value,$Content=>$Content)


有趣的是,我在发布时使用了'Content',我的服务器cgi使用$param->{'field'}来访问作为此内容一部分的参数。当我获取并尝试添加“内容”时,没有这样的标题,因此我得到了错误。所以我想知道当我发出GET请求时,如何访问CGI中的$field\u name键值对?我想我应该做一个测试并转储所有传入的内容。我在服务器CGI端做了一个测试,但在转储中找不到任何键/值对。我正在做“我的$query=newCGI;我的$rcvd_数据=Dumper($query);打印$rcvd_数据,我得到:$VAR1=bless({.parameters'=>[],'use_tempfile'=>1',.charset'=>'ISO-8859-1','.fieldnames'=>{},'param'=>{},header_printed'=>1,'escape'=>1},'CGI');这是一个问题吗?其余部分在哪里?(代码、期望的行为等)?是的,这是一个问题。我应该启动另一个线程吗?所有信息都在那里。问题是,“键值对在哪里?”?它们不会出现在转储程序输出中。“我想将此答案(您的答案)标记为正确,但我在CGI服务器端找不到字段值,所以我不知道。什么键值对?信息不在那里。就像我说的,您的代码在哪里?期望的行为或输出是什么?