POST problems - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


POST problems

I have a form that uses the POST method to send data to a CGI script. The form looks like this:




Problem is, nothing is received by message.cgi. I check which REQUEST_METHOD is being used and it tells me GET. When I read from STDIN, I get nothing.

Now when I modify message.cgi so it works for the GET method and type in the values in the URL, it works so it's not a server problem.

The code in message.cgi is this,

read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
print "Buffer: $buffer

...pretty standard stuff but there is nothing in buffer.

Any suggestions?




  • hey, i dunno why thats not working but anyway ive got a subroutine that'l make life alot easier for you...

    sub read_input
    local ($buffer, @pairs, $pair, $name, $value, %FORM);
    $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
    if ($ENV{'REQUEST_METHOD'} eq "POST")
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    } else
    $buffer = $ENV{'QUERY_STRING'};
    # Split information into name/value pairs
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs)
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%(..)/pack("C", hex($1))/eg;
    $FORM{$name} = $value;

    now all thats left to is use it:
    my %query = &read_input;

    so say your form had a textbox called "email" you use:
    to get whatever the submitter entered, also it will automatically fix up any special characters sent into the form.

    Hope it works for you!!
Sign In or Register to comment.