I have an interesting problem. We have a client that wants to use webmethods to send us xml data via an http post. I've tried using cgi.pm, but haven't had much success with it. I've rolled my own (I can see the steam rising from merlyn). First, I'd like to know if I can get cgi.pm to work properly for me. If I can't, I'd like any input with potential problems with my code.
This is the cgi script I wrote. It needs to take the content and not parse, or decode anything and write it out to a file.
use strict;
use CGI;
if ($ENV{'CONTENT_LENGTH'} > 0 && $ENV{'REQUEST_METHOD'} eq "POST" &&
+$ENV{"CONTENT_TYPE"} =~ m|^text/xml|){
my $buffer;
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
if (length($buffer) != $ENV{'CONTENT_LENGTH'}){
# code to return 400
print "400\n";
exit;
}
open (FILE,">d:\\test\\test");
print FILE $buffer;
close (FILE);
# code to return 200
print "200\n";
exit;
}
# code to return 400
print "400\n";
exit;
Here is a test agent program I wrote that mimics how they will send us data:
use LWP::UserAgent;
use strict;
my $ua = new LWP::UserAgent;
my $content = <<EOF;
<test>
<test2>test4&;</test2>
<test>
EOF
my $req = new HTTP::Request (POST=>'http://test:test@localhost/cgi-bin
+/http/upload.pl');
$req->content_type('text/xml');
$req->content("$content");
print $ua->request($req)->as_string;