cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

OK, so maybe I'm too close, but here's a summary:
#!/usr/bin/perl -w use strict; use CGI; $|++; # # this is the receiving script run under http # receiving data from an https page - same result # in IE5 and in Mozilla 0.9.5 # my $q = new CGI; print $q->header; # buffer my $buffer = ''; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); print "CONTENT_LENGTH = $ENV{'CONTENT_LENGTH'}\n\n"; # 109 - OK print "Buffer = $buffer\n\n"; # shows $buffer is empty # try to read vars the 'standard' CGI way... for ($q->param()) { print "$_ = ".$q->param($_)."\n"; } # prints nothing

OK, so this is very perplexing. Changing https form method to get sends the data OK, but I don't want to do this unless I have to (apache logging of QS in undesirable, though "workaroundable".

Any thoughts? I'm stumped. I bet this is a very, very simple thing and I'm just blinded to it...

cLive ;-)

--
seek(JOB,$$LA,0);

Replies are listed 'Best First'.
Re: Bizarre CGI.pm behaviour or just me?
by tachyon (Chancellor) on Feb 16, 2002 at 21:31 UTC

    When you create a new CGI object CGI.pm will read 'CONTENT_LENGTH' bytes from STDIN so the buffer will inevitably be empty as you have already read 'CONTENT_LENGTH' bytes from STDIN when you made your new CGI object. To check you are actually getting data just run this script (less is more):

    #!/usr/bin/perl read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); print "Content-type: text/plain\n\n$buffer"

    If you find that this proves that data is getting to your script on STDIN have a look at what is in the CGI object like this:

    #!/usr/bin/perl use Data:Dumper; use CGI; $q = new CGI; print $q->header; print '<pre>'.$q->escapeHTML(Dumper($q)).'</pre>';

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Bizarre CGI.pm behaviour or just me?
by stephen (Priest) on Feb 16, 2002 at 20:01 UTC
    I don't see an obvious error-- you might want to try
    my $bytes_read = read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); print "Bytes read: $bytes_read\n";
    Aside from that, does the script work OK outside of SSL? Might be a server problem-- which server are you using... Apache-SSL? Which version?

    stephen

Re: Bizarre CGI.pm behaviour or just me?
by Dog and Pony (Priest) on Feb 16, 2002 at 20:34 UTC
    Some questions:
    • Does it work if you post it somewhere else?
    • Does it work if you post it to the same computer?
    • Is it some kind if upload or other that demands that you use a special enctype such as "multipart/form-data"?
    • Silly question, but: your form is correct? What happens if you post something else to the same place?
    • And what happens if you post something from someplace else to the same place?

    As you can see, I am trying to isolate the problem, and create a rudimentary "test suite". This is how I usually track strange problems. :)

(cLive ;-) Re: Bizarre CGI.pm behaviour or just me?
by cLive ;-) (Prior) on Feb 16, 2002 at 22:49 UTC
    Thank you tachyon. In writing the dummy script, I left all the "use" statements in place for various modules that the (quite old) original script used. (and of course, for brevity I left them out of my post here - d'oh!)

    amongst them was a "common" module that parsed form data into a Hash %common::field.

    So, when CGI is used after, STDIN is empty because it has already been read.

    And I spent 2 F&*^%ing hours looking for a complicated solution. Ah well, always the way...

    Thanks all for your comments. Now all I have to do is find out which scripts use the "common" module and slowly move them over to CGI...

    cLive -;)

    --
    seek(JOB,$$LA,0);

      And I spent 2 F&*^%ing hours looking

      I reckon we've all been there and done that. Some of us have even done it twice ;-) Glad you have got it figured.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

(cLive ;-) Re: Bizarre CGI.pm behaviour or just me?
by cLive ;-) (Prior) on Feb 16, 2002 at 19:53 UTC
    Oh, and I've validated the sending form OK, and tried putting a seek(STDIN,0,0) b4 the read (I can't recall if that's needed or works, but I tried it anyway...)

    cLive ;-)

    --
    seek(JOB,$$LA,0);