B
Bill Gerba
Hi,
I've run into a problem with CGI.pm. I want to use my own generic
code to actually capture the raw POST data from a form submission and
store the whole thing to a file. After I've caught the entire POST
stream, I then want to load all of the data from the file back into
STDIN and create a new CGI object that will read the data in there and
parse it out for me. Attached is the code that I'm using, and I'm
submitting from a very simple HTML form with a few text boxes and
select widgets (Perl 5.6.1 and Apache on Linux, if it's important).
#!/usr/bin/perl -w
use strict;
use Data:
umper;
use CGI;
# First, grab the HTTP POST stream and dump it into a file.
my ($TMP,$DATA);
open($TMP,">","posted_data.txt");
while (read STDIN, $DATA, 1024) {
print $TMP $DATA;
}
close $TMP;
# Next, open the file into STDIN so CGI.pm can read it
open(STDIN,"posted_data.txt") or die "can't open temp file: $!";
$| = 1;
# Print out the data from the HTTP POST as CGI sees it.
my $cc = new CGI;
my %v = $cc->Vars;
print $cc->header();
print Dumper(\%v);
When I run this, it saves the file correctly (all of the data and
headers are there), but I get a cryptic error message: "Filehandle
STDOUT opened only for input at test.cgi line 22."
AFAIK, I'm not doing anything at all to STDOUT, and CGI doesn't seem
to think that there's anything in STDIN at all. But if I don't make
the CGI object and just do a while (<STDIN>) { print; } I get all of
my data out fine. What am I doing wrong, and how can I get CGI to see
the data in STDIN?
TIA,
Bill
I've run into a problem with CGI.pm. I want to use my own generic
code to actually capture the raw POST data from a form submission and
store the whole thing to a file. After I've caught the entire POST
stream, I then want to load all of the data from the file back into
STDIN and create a new CGI object that will read the data in there and
parse it out for me. Attached is the code that I'm using, and I'm
submitting from a very simple HTML form with a few text boxes and
select widgets (Perl 5.6.1 and Apache on Linux, if it's important).
#!/usr/bin/perl -w
use strict;
use Data:
use CGI;
# First, grab the HTTP POST stream and dump it into a file.
my ($TMP,$DATA);
open($TMP,">","posted_data.txt");
while (read STDIN, $DATA, 1024) {
print $TMP $DATA;
}
close $TMP;
# Next, open the file into STDIN so CGI.pm can read it
open(STDIN,"posted_data.txt") or die "can't open temp file: $!";
$| = 1;
# Print out the data from the HTTP POST as CGI sees it.
my $cc = new CGI;
my %v = $cc->Vars;
print $cc->header();
print Dumper(\%v);
When I run this, it saves the file correctly (all of the data and
headers are there), but I get a cryptic error message: "Filehandle
STDOUT opened only for input at test.cgi line 22."
AFAIK, I'm not doing anything at all to STDOUT, and CGI doesn't seem
to think that there's anything in STDIN at all. But if I don't make
the CGI object and just do a while (<STDIN>) { print; } I get all of
my data out fine. What am I doing wrong, and how can I get CGI to see
the data in STDIN?
TIA,
Bill