How do I handle a POST request in Perl and FastCGI?

Posted by Peterim on Stack Overflow See other posts from Stack Overflow or by Peterim
Published on 2010-04-18T20:43:26Z Indexed on 2010/04/20 1:03 UTC
Read the original article Hit count: 449

Filed under:
|
|

Unfortunately, I'm not familiar with Perl, so asking here. Actually I'm using FCGI with Perl.

I need to 1. accept a POST request -> 2. send it via POST to another url -> 3. get results -> 4. return results to the first POST request (4 steps).

To accept a POST request (step 1) I use the following code (found it somewhere in the Internet):

$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ($ENV{'REQUEST_METHOD'} eq "POST") {
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {
    print ("some error");
}

@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%(..)/pack("C", hex($1))/eg;
    $FORM{$name} = $value;  
}

The content of $name (it's a string) is the result of the first step. Now I need to send $name via POST request to some_url (step 2) which returns me another result (step 3), which I have to return as a result to the very first POST request (step 4).

Any help with this would be greatly appreciated.

Thank you.

© Stack Overflow or respective owner

Related posts about perl

Related posts about fcgi