in reply to STDIN not working, STDIN hanging

If you really want to reinvent the wheel, you can read the query string as follows:

my $query; my $req_method = $ENV{REQUEST_METHOD}; if ($req_method eq 'POST') { read STDIN, $query, $ENV{CONTENT_LENGTH}; # <-- } elsif ($req_method eq 'GET') { $query = $ENV{QUERY_STRING}; }

(But it's not recommended...)

Replies are listed 'Best First'.
Re^2: STDIN not working, STDIN hanging
by FRIENDOFGOD (Initiate) on Jul 01, 2010 at 21:43 UTC

    2010-07-01

    Your example worked,

    and when I replaced,

    read STDIN, $query, $ENV{CONTENT_LENGTH}; # <--

    with,

    $query=<STDIN>; # <--

    it also worked, only when it was loaded directly, but when a form was sent to it, it did the continuous load.

    Works when loaded directly,
    Continuous when form sent to it...

    #! perl my $query; my $req_method = $ENV{REQUEST_METHOD}; if ($req_method eq 'POST') { $query=<STDIN>; print $query; # <-- } # END

    Works when loaded directly,
    Continuous when form sent to it...

    #! perl my $query; if ($ENV{REQUEST_METHOD} eq 'POST') { $query=<STDIN>; print $query; # <-- } # END

    One question is, why did it not work before, when the form was method="post" --

    Your response indicates that <STDIN> handles POST...

    if ($req_method eq 'POST') {$query=<STDIN>;}

    and $ENV{QUERY_STRING} handles GET...

    elsif ($req_method eq 'GET') {$query = $ENV{QUERY_STRING};}

    Did it have anything to do with sockets as the previous response indicates ?

    (But it's not recommended...)

    Why is it not recommended ?

    - Look For God