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

I try to build a little HTTP server with IO::Socket.
I want to get the contents of submitted by POST.
How do I analyse the http request?Thank you.

Replies are listed 'Best First'.
Re: if method is POST...
by btrott (Parson) on May 04, 2000 at 20:06 UTC
    Essentially, you:
    • accept a client socket
    • read the request line (GET foo or POST foo)
    • read the rest of the request headers (until you read a blank line)
    • read the body of the request--this is the content as submitted by a POST request.
    Take a look at HTTP::Daemon. You can either use the module or take a look at how it works, to see how you can write your own server.
RE: if method is POST...
by haggs (Initiate) on May 05, 2000 at 04:44 UTC
    If this is just an academic excercise I would suggest www.ietf.org so that you can read all about how http protocol needs to be implemented. If this is something that you need to get something done, see the first reply. Otherwise the traffic over the socket will look something like this.
    HTTP 1.0 POST
    URL:foo
    User-Agent: foo

    foo=bar&perl=cool

    note that there is a blank line btw the header and the URL params
Re: if method is POST...
by athomason (Curate) on May 04, 2000 at 19:44 UTC
    What you want may already have been done... check out perl-server.