0
我有一個用於文件下載的特例。我需要爲大文件進行分塊下載,並且需要在下載之前將參數傳遞給CGI腳本。LWP GET大文件下載
它確實是一個REST接口。我在互聯網上搜索了很多東西,下載部分有很多東西,參數部分有很多東西,但是當我把它們放在一起時,我會遇到錯誤。另外請注意,我以類似的方式進行POST,並且它工作正常。這裏是我的代碼剪斷:
# $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>
有趣,所以我用「內容'當我POST和我的服務器CGI使用$參數 - > {'字段'}來訪問這些內容的一部分參數。當我GET並嘗試添加'Content'時,沒有這樣的頭部,所以我得到錯誤。所以我想知道如何在我放置GET請求時訪問我的CGI中的$ field_name鍵值對?我想我應該做一個測試並轉儲所有內容。 – tradetree
我在服務器CGI端做了一個測試,並且在轉儲中找不到任何我的鍵/值對。我正在做「我的$查詢=新的CGI;我的$ rcvd_data = Dumper($查詢);打印$ rcvd_data,並且我得到:$ VAR1 = bless('{012,'.parameters'=> [], 'use_tempfile'= > 1, '.charset'=> 'ISO-8859-1', '.fieldnames' => {}, 'PARAM'=> {}, ' .header_printed」 => 1, '逃離' => 1 },'CGI'); – tradetree
這是一個問題嗎?剩下的部分在哪裏?(代碼,期望的行爲等)? – ikegami