CGI - Not getting POST Variables
vi_srikanth
created: 2006-08-03 07:44:43

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'; filename='");
	_LIT8(KFileCompletion,"'");
		
	_LIT8(KContentEmail,"Content-Disposition: form-data; name='accemailid'");
	_LIT8(KContentComment,"Content-Disposition: form-data; name='comment'");

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

Thanks
Srikanth

Re: CGI - Not getting POST Variables
created: 2006-08-03 08:16:03
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]
Re^2: CGI - Not getting POST Variables
created: 2006-08-03 09:39:24

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

Re^3: CGI - Not getting POST Variables
created: 2006-08-03 09:49:09

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)

Re^4: CGI - Not getting POST Variables
created: 2006-08-03 09:52:18
If there is problem with C++ web client, then the PHP script should also NOT work... right? But, it is working perfectly!!!
Re^5: CGI - Not getting POST Variables
created: 2006-08-03 10:12:30

Try to sniff the connection -- there's something different going on in the encoding the web browser is using for the HTML form, and the the C++ client send. It may be really subtle, too -- the server might send a different Accept header when it's a PHP script, which generates different behaviour in the C++ program.

So, I'll repeat myself -- sniff the connection. Something different is going on, or it wouldn't be broken. Look for what's different, and it can be a clue in what needs to be fixed, and how to fix it. Debugging problems is more than just looking at symptoms and surface effects -- you need to dig into why something is happening, not just what is happening.

The only thing I can think of right now is that the server is sending headers that it accepts some sort of compression, or a language encoding that I'm not familiar with, but without knowing what's being sent between the two systems, I don't want to make a false diagnosis. (would you want a doctor to just glance at you for a few seconds, then tell you that you need to have a major organ internal removed?)

(and, if you come away with learning how to trouble shoot these sorts of things, you don't have to come back and ask every time ... and might be able to help others, too.)

Re^4: CGI - Not getting POST Variables
created: 2006-08-03 12:17:32
Header compression would certainly seem a logical culprit, I would try something like ethereal to sniff what is actually being sent by the client.

jdtoronto

Re^5: CGI - Not getting POST Variables
created: 2006-08-05 07:48:23

Hi

I do not have enough rights to install ethereal or tcpdump in the server :(

By the way, I tried to print the STDIN value using the code

read (STDIN, $form_info, $size_of_form_info);
print TMP $form_info ;

Here is its output:

--AaB03x
Content-Disposition: form-data; name='userfile'; filename='MofTestFil.jpg'
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

��JFIFHH�C



▒▒�C
!2"�

�}!1AQa"q#BR�$3br
▒▒%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������

�w!1AQaq"B      #3Rbr
$4�▒▒&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������
                                                                  ?S((((((((((((
--AaB03x
Content-Disposition: form-data; name='accemailid'

--AaB03x
Content-Disposition: form-data; name='comment'


--AaB03x
Content-Disposition: form-data; name='tag'


--AaB03x
Content-Disposition: form-data; name='privacy'

Public
--AaB03x--

You can see that all the other form-data fields are empty! The whole values is in the first field! Any idea?

Thanks
Srikanth

Re^6: CGI - Not getting POST Variables
created: 2006-08-06 04:09:53
Your browser or html is broken

perlmonks.org content © perlmonks.org and Anonymous Monk, jdtoronto, jhourcle, vi_srikanth

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03