jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

I feel like I am having a stupid moment! On a normal HTTP server when the REQUEST_METHOD is POST you pull CONTENT_LENGTH characters from STDIN. But when using HTTPServer (v1.1.1) I only get the following environment variables:

2005/06/29 16:17:51 - POST /foo/bar.pl Method => POST Use of uninitialized value in concatenation (.) or string at G:\EngDat +a\EP2058 InContact\EP2058-002\server_01.pl line 42. Query => SERVER_NAME ->> mercury SCRIPT_NAME ->> /foo/bar.pl REMOTE_ADDR ->> 64.105.135.235 SERVER_ADMIN ->> webmaster@mercury SERVER_PROTOCOL ->> HTTP/1.1 REQUEST_METHOD ->> POST <?xml version ->> "1.0"?> <campaign menuid="9839-2" callid="0" action="5" duration="0" comment=" +test"/> REMOTE_NAME ->> h-64-105-135-235.lsanca54.covad.net GATEWAY_INTERFACE ->> CGI/1.1 SERVER_SOFTWARE ->> Net::HTTPServer/1.1.1 HTTP_USER_AGENT ->> Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpReq +uest.5)
The content I am looking for is this XML:
<?xml version ->> "1.0"?> <campaign menuid="9839-2" callid="0" action="5" duration="0" comment=" +test"/>
The ->> is my separator where I print the list. My poor little brain cannot see how I am supposed to get the content! Help me please!

jdtoronto

Replies are listed 'Best First'.
Re: In HTTPServer - how do I get POST content?
by ikegami (Patriarch) on Jun 29, 2005 at 21:10 UTC
    Are you sure the client put the necessary blank line between the header and the content? It's treating your content as a part of the header. (Note how the = after <?xml version was converted to ->>.)
      Trouble is the client isn't mine! It is an API provided by a telco. It looks as though there is a blank line, but HTTPServer is somehow splitting the following line - I suppose it is doing it on the '=' ?

      Maybe I need to look at other modules as well, pity, this one seemed to have such potential.

      jdtoronto

        Would it be possible to pre process the content by hand? Just thinking out loud, a linke to this HTTPServer would be helpful. BTW the first few lines have => while the rest have ->>


        ___________
        Eric Hodges
Re: In HTTPServer - how do I get POST content?
by Adrade (Pilgrim) on Jun 30, 2005 at 06:11 UTC
    Wait a sec... this display above is an abstract list of all the environmental variables available, right? So, it looks like your webserver is putting the input in the REQUEST_METHOD env var - if this is the case, then $ENV{'REQUEST_METHOD'} =~ m/\n(.*)/s; or on wherever your server's storing that env var.

    Now, as I reread, the most likely scenerio is that you're reading the env content from a file, in which case, you would
        m/REQUEST_METHOD[^\n]+\n(.*?)\n[A-Z_]{4,}/s

    Let me quickly state that this last regex is horrible as it would stop in the middle of your input if it reached a newline and then 4 capital letters - but if you have a specific sort of input, it may work for you.

    Hope it helps,
      -Adam

    --
    Impossible! The Remonster can only be killed by stabbing him in the heart with the ancient bone saber of Zumakalis!

Re: In HTTPServer - how do I get POST content?
by jdtoronto (Prior) on Jul 05, 2005 at 16:22 UTC
    Esteemed Monks,

    A quick update: Seems that my problem is actually a bug in the module. When I use HTTP::Daemon the answers make sense. When I have some time I will document the problem and submit it to the module author.

    jdtoronto