23skiddoo has asked for the wisdom of the Perl Monks concerning the following question:
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@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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simple web server to ingest POST
by haukex (Archbishop) on Jun 08, 2022 at 16:22 UTC | |
by 23skiddoo (Beadle) on Jun 08, 2022 at 17:43 UTC | |
by haukex (Archbishop) on Jun 08, 2022 at 19:04 UTC | |
by haukex (Archbishop) on Jun 08, 2022 at 18:10 UTC | |
by 23skiddoo (Beadle) on Jun 08, 2022 at 18:51 UTC |