Well folks, I had hoped to be able to do this in just a couple of day by modifying a prior sample. No such luck.

I want to make a Restfull server that uses mostly canned (I tweak with current data and message number with regex substitutions) answers to 2 procedure names. It would be a "TAXII Discovery Service".

TAXII is XML, so HTTP POST 'queries' are irrelevant, but the HTTP heading, and the XML body are critical.

So far I have been working off of the large example in this module.
http://search.cpan.org/~bps/HTTP-Server-Simple-0.51/lib/HTTP/Server/Simple.pm

I insert into the 'resp_hello()' subroutine reading STDIN(empty), or $cgi->param('POSTDATA') (empty string), or `set>/tmp/environment.txt` (no XML variables).

The input I send to the interface is this:

POST /hello HTTP/1.1 Proxy-Connection: keep-alive Host: 127.0.0.1 Content-type: application/xml Accept: application/xml Cache-Control: no-cache X-TAXII-Services: urn:taxii.mitre.org:services:1.1 X-TAXII-Protocol: urn:taxii.mitre.org:protocol:http:1.0 Accept-Language: en-US,en;q=0.8 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KH +TML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 Content-length: 98 <Discovery_Request xmlns="http://taxii.mitre.org/messages/taxii_xml_bi +nding-1.1" message_id="1"/>
My mods to the example are :
my $who = $cgi->param('name'); my $msg = $cgi->param('POSTDATA'); my @keywords = $cgi->keywords; print join(',',@keywords); print "this is a simple text string who=<$who> param('POSTDATA')=<< +$msg>>>\n"; print $cgi->header, $cgi->start_html("Hello"), $cgi->h1("Hello $who!"), $cgi->end_html; }
I get in return:
HTTP/1.0 200 OK this is a simple text string who=<> param('POSTDATA')=<<>>> Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Hello</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <h1>Hello !</h1> </body> </html>
(Note that this output shows the $who variable was also an enpty string!)

Based upon the CGI.pm page (http://perldoc.perl.org/CGI.html):

If POSTed data is not of type application/x-www-form-urlencoded or multipart/form-data, then the POSTed data will not be processed, but instead be returned as-is in a parameter named POSTDATA. To retrieve it, use code like this: my $data = $query->param('POSTDATA');
Of course, all documentation of creating a 'query' is the result of a CGI->new() sort of thing. But the page for the server says the input arg is a CGI object (already made).

I can't find the Body line ('<Discovery_Request...>') reading STDIN, nor the param() approach above, nor in any environment variables.

I chose this module, because it appeared simple, had a good example, and didn't involve huge amounts of study to just install it. I also thought it would perform as the limited docs repesented.

It is always better to have seen your target for yourself, rather than depend upon someone else's description.


In reply to Finding XML POST data in HTTP::Server::Simple::CGI by Wiggins

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.