vi_srikanth has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I am having a CPP program which calls the Perl script http://mywebsite.com/upload.pl. This CPP program passes a few POST variables (userfile, accemailid and comment). But, I am not getting ANY post vairable in the upload.pl! Here is the code snippet of the upload.pl:

my $query=new CGI; my $emailid = $query->param('accemailid'); print TMP time; # Just to check whether the file gets executed print TMP $emailid; # TMP is a file handler of a temp file

The above program gets executed(time gets printed), but I am not getting any value in the variable $emailid! Instead of through CPP program, if I try the URL of the CGI script through a HTML form submit, it works precisely (both GET as well as POST).

I wrote a PHP script which almost does the above. Here is the code:

$emailid = $_POST['accemailid']; $logfile = "/tmp/in/log.txt"; $fh = fopen($logfile, 'a') or die("can't open file"); fwrite($fh, $emailid); fclose($fh);
It works precisely through CPP program!!!!

Here is the CPP code snippet:

_LIT8(KPostUri, "http://mywebsite.com/upload.pl"); _LIT8(KDataStart,"--AaB03x"); _LIT8(KCrlf,"\r\n"); _LIT8(KContent,"Content-Disposition: form-data; name='userfile'; f +ilename='"); _LIT8(KFileCompletion,"'"); _LIT8(KContentEmail,"Content-Disposition: form-data; name='accemai +lid'"); _LIT8(KContentComment,"Content-Disposition: form-data; name='comme +nt'");

Any idea why the perl script is not getting the variables? Kindly help.

Thanks
Srikanth

Replies are listed 'Best First'.
Re: CGI - Not getting POST Variables
by jdtoronto (Prior) on Aug 03, 2006 at 12:16 UTC
    Why not try dumping the query and see what is there?
    use Data::Dumper; my $query=new CGI; print TMP Dumper($query); my $emailid = $query->param('accemailid'); print TMP time; # Just to check whether the file gets executed print TMP $emailid; # TMP is a file handler of a temp file
    jdtoronto

      Hi

      This is the dump:

      $VAR1 = bless( { '' => [ '??JFIFdd?Duckyd?Adobed??? !1AQa"q#?BR??$ 3%C!1AQaq"??#?Rb 3r?$? ???R}}}+?@*U?S0+???y:???? +?tvY?Md?HC R(A\\6\'?O?m)@?k ?\\+??s?pa9?lR)?I6 ?Z*ZzisN?\'?~f, W??RQh?%@?z+J?e} ??+wR+X?k?:@fiD?pKSgM:?7$?/?+?(>W???s?ib??uS?I6L ?OT?>C?:X?Z)P?(@?+??Q +?>k?:|}:An4Qx?MP/C?IuL3 ?V?O?S??!UJ\'?Z?3j??u?w?-M???$????z+l??Mj?`i?Q?)N-?z?hwG? +?|t+?]8R??_?$???P|??6!0?\\+???,s7E8RM e�I.ꐋZj_M?�5� X?�, . . . More such junk . . 'ztjgj@jmj.com', '', 'Myapp', 'Public' ], '.parameters' => [ '' ], '.charset' => 'ISO-8859-1', '.etab' => 1, '.elid' => 1, '.fieldnames' => {}, '.header_printed' => 1, 'escape' => 1 }, 'CGI' );

      I dont know why I am getting junk characters. Instead of calling the CGI program through CPP program, if I try through HTML form (Get or Post) the Dump seems to be perfect, i.e. I get all the parameters without any junk characters. Any idea?

      Thanks
      Srikanth

        It sounds to me like the problem's in the C++ web client, not the perl backend. You might want to sniff the connection, and see exactly what the client is sending, as it doesn't seem to be serializing the values correctly. (or it's using some sort of encoding that I'm not familiar with, and the perl script doesn't understand)