0
這篇文章是關於LWP GET large file download的相關工作。這篇文章是關於嘗試在頭中錯誤地傳遞參數時LWP的錯誤。現在我發佈了我所做的更改以及我如何嘗試調試該方法。這個討論應該對那些對POST和GET頭信息感興趣的人以及服務器在使用CGI包的時候收到的信息很有幫助。這不是網上很容易找到的信息。LWP獲取大文件下載頭部丟失
這裏是我的客戶端代碼剪斷:
my $bytes_received = 0; # vars used below are set prior to this point
my $filename = $opt{t}."/$srcfile";
open (FH, ">", "$filename") or $logger->error("Couldn't open $filename for writing: $!");
my $ua = LWP::UserAgent->new();
my $target = $srcfile;
my $res = $ua->get(
$url,
':content_cb' => \&callback,
'api' => 'olfs', # Note attempted use of different types of quotes had no impact
"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;
}
這裏是服務器剪斷(CGI腳本):
my $query = new CGI;
my $rcvd_data = Dumper($query);
print $rcvd_data;
這裏是一個GET輸出:
$VAR1 = bless({
'.parameters' => [],
'use_tempfile' => 1,
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'param' => {},
'.header_printed' => 1,
'escape' => 1
}, 'CGI');
這裏是一個POST請求的客戶端:
my $ua = new LWP::UserAgent();
local $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1;
my $req =
POST
$url,
'Content_Type' => 'form-data',
'Content' => {
"api" => 'olfs',
"cmd" => 'wfile',
"target" => $target,
"tsize" => $file_size,
"bs" => $bs,
"filename" => [ $file ] };
# HTTP::Message calls set_content, which appears to set the subroutine for content
# LWP::UserAgent
# LWP::Protocol::file::request sends content in chunks
#
$req->content($req->content());
$logger->info("Uploading: $file");
my $resp = $ua->request($req);
這裏是服務器上的輸出,就像從POST之前,但現在:
'.parameters' => [
'cmd',
'bs',
'api',
'target',
'filename',
'tsize'
],
'use_tempfile' => 1,
'.tmpfiles' => {
'*Fh::fh00001random23' => {
'info' => {
'Content-Type' => 'text/plain',
'Content-Disposition' => 'form-data; name="filename"; filename="random23"'
},
'name' => bless(do{\(my $o = '/usr/tmp/CGItemp33113')}, 'CGITempFile'),
'hndl' => bless(\*Fh::fh00001random23, 'Fh')
}
},
'.charset' => 'ISO-8859-1',
'.fieldnames' => {},
'param' => {
'cmd' => [
'wfile'
],
'bs' => [
'buffer1'
],
'api' => [
'olfs'
],
'target' => [
'random23'
],
'tsize' => [
'1073741824'
],
'filename' => [
$VAR1->{'.tmpfiles'}{'*Fh::fh00001random23'}{'hndl'}
},
'escape' => 1,
'.header_printed' => 1
}, 'CGI');
總之,你可以在POST看到傾倒的「鑰匙」 /「值」對,即「target => random23」。在GET轉儲中,我沒有發現我在客戶端提交的任何鍵或值。可以解釋一下,或者我需要做些什麼來提取CGI腳本中的鍵/值對?
是的,這有效。謝謝。使用POST可以將參數添加到「內容」,而由於GET沒有「內容」,您必須構建一個URI。所有的URI類正在做的是將通常爲瀏覽器URI所做的&key = value結構放在一起。 – tradetree