我正在尝试使用CGI脚本接受并保存使用HTTP POST发送zip文件的程序中的文件。为什么我的.zip文件在HTTP文件上传后损坏?
在HTTP标头的MIME部分,它看起来是这样的:
Content-Disposition: form-data; name="el_upload_file_0"; filename="BugReport.zip";\r\n
Content-Type: application/octet-stream\r\n\r\n
在我的CGI代码,我使用的是这样的:
use CGI;
use strict;
my $cgi = CGI->new;
my $upload_file = $cgi->upload('el_upload_file_0');
my $time = time;
my $filename = "/tmp/$time.zip";
open TMP, ">$filename";
binmode TMP;
while (<$upload_file>) {
print TMP $_;
}
close TMP;
是不断得到保存的文件是某种越来越腐败,并不是一个有效的zip文件。 HTTP请求由C#应用程序发送,可能它发送的是损坏的zip文件,但我对此表示怀疑。我能做些什么来进一步排除故障?