Hi! It's been a while! So I have a project where I need to have a server running just to ingest XML files POSTed from a vendor's server. I have something basic working but my responses after ingesting the XML are throwing errors on the vendor's side. Here's what I have:

#!/usr/bin/perl use strict; use warnings; { package Four51Listener; use HTTP::Server::Simple::CGI; use base qw( HTTP::Server::Simple::CGI ); use EGA::Utils qw( TimeStamp ); # a set of custom functions my %dispatch = ( '/toMFF' => \&toMFF, ); sub handle_request { my ( $self, $cgi ) = @_; my $path = $cgi->path_info(); my $handler = $dispatch{ $path }; if ( ref( $handler ) eq 'CODE' ) { $handler->( $cgi ); print $cgi->header( -type => 'text/xml', -charset => 'ascii' ) +, response_ok(); } } sub toMFF { my $cgi = shift; my $xml = $cgi->param( 'POSTDATA' ); } sub response_ok { my $timestamp = TimeStamp(); $timestamp =~ s/\s/T/; my $response = <<EOF; <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.1.009/cXML.d +td"> <cXML payloadID="foo&commat;ceprinter.com" xml:lang="en-US" timestamp= +"$timestamp"> <Response> <Status code="200" text="OK" /> </Response> </cXML> EOF return $response; } } my $pid = Four51Listener->new(8888)->background(); print "Kill $pid to stop server.\n";

The server doing the POST expects XML back but I keep getting errors about "protocol violation". I'm not opposed to using a framework like Dancer2 or Mojolicious, but I'm not quite sure how to do so for something like this.

Any ideas?

In reply to Simple web server to ingest POST by 23skiddoo

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.