Perl scripts on Apache not retrieving POST data












0















I'm trying to get a pre-existing PERL web application running on my local MAMP apache2 server and am having problems getting post data. The app uses cgi.pm to try to grab data from $cgi->param, but param is always empty even when properly formatted post data is sent in x-www-form-urlencoded format.



Additionally, STDIN is always empty and throws an error if not prefaced with *.



hello-world-form.cgi:



#!/[localpath]/perl5/perlbrew/perls/perl-5.24.0/bin/perl -d

use strict;
use warnings;

print "Content-type: text/htmlnn";
print qq(
<!doctype html>
<html>
<body>
<form action="hello-world.cgi" method="POST">
<input type="text" name="myparam" />
<input type="submit" value="submit post var" />
</form>
</body>
</html>
);


hello-world.cgi:



#!/[localpath]/perlbrew/perls/perl-5.24.0/bin/perl -d

use strict;
use warnings;
use CGI;

my $q = CGI->new();

print "Content-type: text/htmlnn";
print "<p>key = " . $q->param('myparam') . "</p>n"; #this is always empty
my @names = $q->param;
foreach my $name (@names) {
print "<p>$name = " . $q->param($name) . "</p>"; #this never runs
}

my $postdata = '';
my $in = *STDIN;
my $bytes = read($in, $postdata, $ENV{'CONTENT_LENGTH'});
print "<p>postdata = $postdata</p>n"; # postdata is empty
print "<p>content length = " . $ENV{'CONTENT_LENGTH'} . "</p>n"; # this number seems correct

foreach my $key (keys %ENV) {
print "<p>$key --> $ENV{$key}</p>n"; # nothing special here
}


httpd.conf:



...
LoadModule cgi_module modules/mod_cgi.so
LoadModule perl_module modules/mod_perl.so
...
ScriptAlias /cgi-bin/ "/[siteroot]/cgi-bin/"
Alias /perl/ "/Applications/MAMP/cgi-bin/"
<IfModule perl_module>
PerlModule ModPerl::Registry
<Location /perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Location>
</IfModule>


I'm running PERL v5.24.0 via perlbrew with these modules:



> perlbrew list-modules

CGI
Date::Parse
Encode::Locale
HTML::Parser
HTML::Tagset
HTTP::Date
HTTP::Message
IO::HTML
LWP::MediaTypes
Perl
Sub::Uplevel
Test::Deep
Test::Needs
Test::NoWarnings
Test::Warn
Try::Tiny
URI


Any ideas?










share|improve this question




















  • 1





    Please show us also how you send the POST request to your Perl program.

    – Corion
    18 hours ago






  • 4





    Also, why do you have -d on the hashbang line of the script?

    – Corion
    18 hours ago






  • 3





    (also, there is no data available on *STDIN because CGI will already have read all available data there. So, please post a Minimal, Complete, and Verifiable example so we can replicate this. This includes the HTML you're using to submit the POST request.

    – Corion
    18 hours ago











  • If you already have access to the POSTed request, I suggest adding it as well, including headers and body etc. I doesn't hurt if people can check actually sent values on their own.

    – Thorsten Schöning
    9 hours ago











  • Brilliant! The -d was the issue here and I'll mark that as the answer. I added the form submit code for posterity (I was using postman to test so I didn't have a sample form file before). And thanks for the explanation on the STDIN. Unfortunately, the actual Perl app now breaks without the -d, but at least I have a new problem to solve. :)

    – curiousgage
    9 hours ago


















0















I'm trying to get a pre-existing PERL web application running on my local MAMP apache2 server and am having problems getting post data. The app uses cgi.pm to try to grab data from $cgi->param, but param is always empty even when properly formatted post data is sent in x-www-form-urlencoded format.



Additionally, STDIN is always empty and throws an error if not prefaced with *.



hello-world-form.cgi:



#!/[localpath]/perl5/perlbrew/perls/perl-5.24.0/bin/perl -d

use strict;
use warnings;

print "Content-type: text/htmlnn";
print qq(
<!doctype html>
<html>
<body>
<form action="hello-world.cgi" method="POST">
<input type="text" name="myparam" />
<input type="submit" value="submit post var" />
</form>
</body>
</html>
);


hello-world.cgi:



#!/[localpath]/perlbrew/perls/perl-5.24.0/bin/perl -d

use strict;
use warnings;
use CGI;

my $q = CGI->new();

print "Content-type: text/htmlnn";
print "<p>key = " . $q->param('myparam') . "</p>n"; #this is always empty
my @names = $q->param;
foreach my $name (@names) {
print "<p>$name = " . $q->param($name) . "</p>"; #this never runs
}

my $postdata = '';
my $in = *STDIN;
my $bytes = read($in, $postdata, $ENV{'CONTENT_LENGTH'});
print "<p>postdata = $postdata</p>n"; # postdata is empty
print "<p>content length = " . $ENV{'CONTENT_LENGTH'} . "</p>n"; # this number seems correct

foreach my $key (keys %ENV) {
print "<p>$key --> $ENV{$key}</p>n"; # nothing special here
}


httpd.conf:



...
LoadModule cgi_module modules/mod_cgi.so
LoadModule perl_module modules/mod_perl.so
...
ScriptAlias /cgi-bin/ "/[siteroot]/cgi-bin/"
Alias /perl/ "/Applications/MAMP/cgi-bin/"
<IfModule perl_module>
PerlModule ModPerl::Registry
<Location /perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Location>
</IfModule>


I'm running PERL v5.24.0 via perlbrew with these modules:



> perlbrew list-modules

CGI
Date::Parse
Encode::Locale
HTML::Parser
HTML::Tagset
HTTP::Date
HTTP::Message
IO::HTML
LWP::MediaTypes
Perl
Sub::Uplevel
Test::Deep
Test::Needs
Test::NoWarnings
Test::Warn
Try::Tiny
URI


Any ideas?










share|improve this question




















  • 1





    Please show us also how you send the POST request to your Perl program.

    – Corion
    18 hours ago






  • 4





    Also, why do you have -d on the hashbang line of the script?

    – Corion
    18 hours ago






  • 3





    (also, there is no data available on *STDIN because CGI will already have read all available data there. So, please post a Minimal, Complete, and Verifiable example so we can replicate this. This includes the HTML you're using to submit the POST request.

    – Corion
    18 hours ago











  • If you already have access to the POSTed request, I suggest adding it as well, including headers and body etc. I doesn't hurt if people can check actually sent values on their own.

    – Thorsten Schöning
    9 hours ago











  • Brilliant! The -d was the issue here and I'll mark that as the answer. I added the form submit code for posterity (I was using postman to test so I didn't have a sample form file before). And thanks for the explanation on the STDIN. Unfortunately, the actual Perl app now breaks without the -d, but at least I have a new problem to solve. :)

    – curiousgage
    9 hours ago
















0












0








0








I'm trying to get a pre-existing PERL web application running on my local MAMP apache2 server and am having problems getting post data. The app uses cgi.pm to try to grab data from $cgi->param, but param is always empty even when properly formatted post data is sent in x-www-form-urlencoded format.



Additionally, STDIN is always empty and throws an error if not prefaced with *.



hello-world-form.cgi:



#!/[localpath]/perl5/perlbrew/perls/perl-5.24.0/bin/perl -d

use strict;
use warnings;

print "Content-type: text/htmlnn";
print qq(
<!doctype html>
<html>
<body>
<form action="hello-world.cgi" method="POST">
<input type="text" name="myparam" />
<input type="submit" value="submit post var" />
</form>
</body>
</html>
);


hello-world.cgi:



#!/[localpath]/perlbrew/perls/perl-5.24.0/bin/perl -d

use strict;
use warnings;
use CGI;

my $q = CGI->new();

print "Content-type: text/htmlnn";
print "<p>key = " . $q->param('myparam') . "</p>n"; #this is always empty
my @names = $q->param;
foreach my $name (@names) {
print "<p>$name = " . $q->param($name) . "</p>"; #this never runs
}

my $postdata = '';
my $in = *STDIN;
my $bytes = read($in, $postdata, $ENV{'CONTENT_LENGTH'});
print "<p>postdata = $postdata</p>n"; # postdata is empty
print "<p>content length = " . $ENV{'CONTENT_LENGTH'} . "</p>n"; # this number seems correct

foreach my $key (keys %ENV) {
print "<p>$key --> $ENV{$key}</p>n"; # nothing special here
}


httpd.conf:



...
LoadModule cgi_module modules/mod_cgi.so
LoadModule perl_module modules/mod_perl.so
...
ScriptAlias /cgi-bin/ "/[siteroot]/cgi-bin/"
Alias /perl/ "/Applications/MAMP/cgi-bin/"
<IfModule perl_module>
PerlModule ModPerl::Registry
<Location /perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Location>
</IfModule>


I'm running PERL v5.24.0 via perlbrew with these modules:



> perlbrew list-modules

CGI
Date::Parse
Encode::Locale
HTML::Parser
HTML::Tagset
HTTP::Date
HTTP::Message
IO::HTML
LWP::MediaTypes
Perl
Sub::Uplevel
Test::Deep
Test::Needs
Test::NoWarnings
Test::Warn
Try::Tiny
URI


Any ideas?










share|improve this question
















I'm trying to get a pre-existing PERL web application running on my local MAMP apache2 server and am having problems getting post data. The app uses cgi.pm to try to grab data from $cgi->param, but param is always empty even when properly formatted post data is sent in x-www-form-urlencoded format.



Additionally, STDIN is always empty and throws an error if not prefaced with *.



hello-world-form.cgi:



#!/[localpath]/perl5/perlbrew/perls/perl-5.24.0/bin/perl -d

use strict;
use warnings;

print "Content-type: text/htmlnn";
print qq(
<!doctype html>
<html>
<body>
<form action="hello-world.cgi" method="POST">
<input type="text" name="myparam" />
<input type="submit" value="submit post var" />
</form>
</body>
</html>
);


hello-world.cgi:



#!/[localpath]/perlbrew/perls/perl-5.24.0/bin/perl -d

use strict;
use warnings;
use CGI;

my $q = CGI->new();

print "Content-type: text/htmlnn";
print "<p>key = " . $q->param('myparam') . "</p>n"; #this is always empty
my @names = $q->param;
foreach my $name (@names) {
print "<p>$name = " . $q->param($name) . "</p>"; #this never runs
}

my $postdata = '';
my $in = *STDIN;
my $bytes = read($in, $postdata, $ENV{'CONTENT_LENGTH'});
print "<p>postdata = $postdata</p>n"; # postdata is empty
print "<p>content length = " . $ENV{'CONTENT_LENGTH'} . "</p>n"; # this number seems correct

foreach my $key (keys %ENV) {
print "<p>$key --> $ENV{$key}</p>n"; # nothing special here
}


httpd.conf:



...
LoadModule cgi_module modules/mod_cgi.so
LoadModule perl_module modules/mod_perl.so
...
ScriptAlias /cgi-bin/ "/[siteroot]/cgi-bin/"
Alias /perl/ "/Applications/MAMP/cgi-bin/"
<IfModule perl_module>
PerlModule ModPerl::Registry
<Location /perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Location>
</IfModule>


I'm running PERL v5.24.0 via perlbrew with these modules:



> perlbrew list-modules

CGI
Date::Parse
Encode::Locale
HTML::Parser
HTML::Tagset
HTTP::Date
HTTP::Message
IO::HTML
LWP::MediaTypes
Perl
Sub::Uplevel
Test::Deep
Test::Needs
Test::NoWarnings
Test::Warn
Try::Tiny
URI


Any ideas?







apache perl cgi.pm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 9 hours ago







curiousgage

















asked 18 hours ago









curiousgagecuriousgage

267




267








  • 1





    Please show us also how you send the POST request to your Perl program.

    – Corion
    18 hours ago






  • 4





    Also, why do you have -d on the hashbang line of the script?

    – Corion
    18 hours ago






  • 3





    (also, there is no data available on *STDIN because CGI will already have read all available data there. So, please post a Minimal, Complete, and Verifiable example so we can replicate this. This includes the HTML you're using to submit the POST request.

    – Corion
    18 hours ago











  • If you already have access to the POSTed request, I suggest adding it as well, including headers and body etc. I doesn't hurt if people can check actually sent values on their own.

    – Thorsten Schöning
    9 hours ago











  • Brilliant! The -d was the issue here and I'll mark that as the answer. I added the form submit code for posterity (I was using postman to test so I didn't have a sample form file before). And thanks for the explanation on the STDIN. Unfortunately, the actual Perl app now breaks without the -d, but at least I have a new problem to solve. :)

    – curiousgage
    9 hours ago
















  • 1





    Please show us also how you send the POST request to your Perl program.

    – Corion
    18 hours ago






  • 4





    Also, why do you have -d on the hashbang line of the script?

    – Corion
    18 hours ago






  • 3





    (also, there is no data available on *STDIN because CGI will already have read all available data there. So, please post a Minimal, Complete, and Verifiable example so we can replicate this. This includes the HTML you're using to submit the POST request.

    – Corion
    18 hours ago











  • If you already have access to the POSTed request, I suggest adding it as well, including headers and body etc. I doesn't hurt if people can check actually sent values on their own.

    – Thorsten Schöning
    9 hours ago











  • Brilliant! The -d was the issue here and I'll mark that as the answer. I added the form submit code for posterity (I was using postman to test so I didn't have a sample form file before). And thanks for the explanation on the STDIN. Unfortunately, the actual Perl app now breaks without the -d, but at least I have a new problem to solve. :)

    – curiousgage
    9 hours ago










1




1





Please show us also how you send the POST request to your Perl program.

– Corion
18 hours ago





Please show us also how you send the POST request to your Perl program.

– Corion
18 hours ago




4




4





Also, why do you have -d on the hashbang line of the script?

– Corion
18 hours ago





Also, why do you have -d on the hashbang line of the script?

– Corion
18 hours ago




3




3





(also, there is no data available on *STDIN because CGI will already have read all available data there. So, please post a Minimal, Complete, and Verifiable example so we can replicate this. This includes the HTML you're using to submit the POST request.

– Corion
18 hours ago





(also, there is no data available on *STDIN because CGI will already have read all available data there. So, please post a Minimal, Complete, and Verifiable example so we can replicate this. This includes the HTML you're using to submit the POST request.

– Corion
18 hours ago













If you already have access to the POSTed request, I suggest adding it as well, including headers and body etc. I doesn't hurt if people can check actually sent values on their own.

– Thorsten Schöning
9 hours ago





If you already have access to the POSTed request, I suggest adding it as well, including headers and body etc. I doesn't hurt if people can check actually sent values on their own.

– Thorsten Schöning
9 hours ago













Brilliant! The -d was the issue here and I'll mark that as the answer. I added the form submit code for posterity (I was using postman to test so I didn't have a sample form file before). And thanks for the explanation on the STDIN. Unfortunately, the actual Perl app now breaks without the -d, but at least I have a new problem to solve. :)

– curiousgage
9 hours ago







Brilliant! The -d was the issue here and I'll mark that as the answer. I added the form submit code for posterity (I was using postman to test so I didn't have a sample form file before). And thanks for the explanation on the STDIN. Unfortunately, the actual Perl app now breaks without the -d, but at least I have a new problem to solve. :)

– curiousgage
9 hours ago














1 Answer
1






active

oldest

votes


















0














Removing the -d from the shebang solves this issue. Kudos to Corion for the answer.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54250230%2fperl-scripts-on-apache-not-retrieving-post-data%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Removing the -d from the shebang solves this issue. Kudos to Corion for the answer.






    share|improve this answer




























      0














      Removing the -d from the shebang solves this issue. Kudos to Corion for the answer.






      share|improve this answer


























        0












        0








        0







        Removing the -d from the shebang solves this issue. Kudos to Corion for the answer.






        share|improve this answer













        Removing the -d from the shebang solves this issue. Kudos to Corion for the answer.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 8 hours ago









        curiousgagecuriousgage

        267




        267






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54250230%2fperl-scripts-on-apache-not-retrieving-post-data%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage