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

Hi I am making a program that will listen for http post. I need to read in the variables passed in by the for. I can read the post but i can't read the form variables. It hangs till I kill the web page that is posting to the program. Here is the program so far.
#!/usr/bin/perl use IO::Socket; $server = '128.113.152.89'; $port = 2345; my $server = new IO::Socket::INET ( Listen => 5, LocalAddr => $server, LocalPort => 2345, Proto => 'tcp' ) ; die "can't set up server" unless $server; $client = $server->accept(); while (<$client>) { print $_; if($_ =~ /POST/){ #want to get posted variables here } } $server->close(); exit;
any help would be great thanks

Replies are listed 'Best First'.
Re: Reading in Post Variables from a socket
by chromatic (Archbishop) on Nov 14, 2002 at 20:16 UTC

    I've done this. It's not trivial. Is there a reason you're not using a standard web server? Apache's really easy to install, and then you can use CGI. Otherwise, if you use HTTP::Daemon, you have to roll your own CGI parser, and they're rather complex.

Re: Reading in Post Variables from a socket
by pg (Canon) on Nov 14, 2002 at 19:38 UTC
    The problem is that you might receive the http request in pieces, that’s normal, so a single socket read does not guarantee you the whole msg, you have to do couple of socket read to get the whole request, then do that m// or whatever you want.
      Forgot to mention, you can determine that you have received the whole request, if you get two blank lines in a row.