I need to POST content from multiple files, so I have read data from multiple files and posting in a Loop. For the first file content post I am getting 200 OK response, for the second file content I am parsing the second file content but it is showing response as 204 No content. Below is my code. Please help me to resolve this.
#! 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;