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;

In reply to CGI.pm problems by c-era

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.