我需要POST多个文件中的内容,所以我从多个文件中读取数据并在循环中发布。对于第一个文件内容帖子我得到200 OK响应,对于第二个文件内容我正在解析第二个文件内容,但它显示响应为204无内容。以下是我的代码。请帮我解决这个问题。
#! usr/bin/perl
require LWP::UserAgent;
use HTTP::Request::Common;
my $EX_OK = 0;
my $EX_TEMPFAIL = -1;
my $url = 'http://jeffbeck.corp.apple.com:6080/parser/post';
my $dir = $ARGV[0];
my $i = 1;
opendir DIR, $dir or die "cannot open dir $dir: $!";
my @filename = map{s/\.[^.]+$//;$_}grep {/\.eml$/} readdir DIR;
foreach $file (@filename){
print "$file \t $dir \n";
$filePath = "$dir/$file.eml";
print "$filePath \n";
#open the file as input and process that.
open (MYFILE, $filePath) or die "Couldn't open file $filePath : $!";
while(<MYFILE>) {
#$mailContent = $mailContent . $_ ;
@content = <MYFILE>;
}
print "###############################################\n";
print @content;
print "\n###############################################\n";
close(MYFILE);
#Getting Message Id and replacing '@' with '_'
my $messageId='';
foreach $mailContent (@content){
if($mailContent =~ m/Message-id: \<(.*)\>/i) {
$messageId = $1;
}
}
$messageId =~ s/[@]/_/gi;
print "My message ID is : $messageId \n";
print "My mail content is : @content \n";
print "++++++++++++++++++++++++++++++++++++++\n";
#Getting mailsize to be logged.
my $response;
my $mailsize = (length(@content)/1024);
my $browser = LWP::UserAgent->new;
#post the same to the URL above with messageid and mailContent
$response = $browser->post($url,
[ 'messageId' => $messageId,
'mailContent' => @content,
]);
print "My response $response\n";
print $response->status_line;
#fetch response and print output.
if( $response->status_line =~ m{200 OK} )
{
print "\tResponse is Success. Code is $EX_OK & message size is $mailsize KB \n";
}
else
{
print "\tResponse is failure. Code is $EX_TEMPFAIL \n";
}
}
closedir DIR;