#!C:\Perl\bin\Perl.exe # locally we can use http://localhost/cgi-bin/formPost.pl use strict; use warnings; # Posted form data has the same format (name value pairs) as the # query string obtained using the GET method but the source if # the data is standard input. # Thus, we do not use the QUERY_STRING environment variable ,which # is empty for the POST method. # Now the environment variable CONTENT_LENGTH returns the number of # bytes of data. This much data can be read using the read method on STDIN my $bytes = $ENV{CONTENT_LENGTH}; my $data; read (STDIN, $data, $bytes); # Output the HTML header information print "Content-type: text/html\n"; print "\n"; # generate a blank line print "\n"; print "\n"; print "
\n"; print "$data\n"; # Split data string into name value pairs and output them as a table print "
The name value pairs are\n"; print "
"; print "\n"; # End the HTML page print "\n";\n"; my @pairs = split(/&/, $data); foreach my $pair (@pairs) { my ($name, $value) = split(/=/, $pair); print "
$name $value \n"; } print "