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:
My mods to the example are :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"/>
I get in return: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; }
(Note that this output shows the $who variable was also an enpty string!)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>
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |