Sending Data To A Form Using the POST Method
by Misha "Scourage" Sole · in Technical Issues · 06/18/2002 (10:18 am) · 4 replies
I was wondering how one would send data to a form using the post method from a script file (.cs). I have been told to use both the TCPObject and the HTTPObject. I have tried to do something like this, but I don't think it is the correct way.
example: (%postdata = data to post)
%conn = new TCPObject(MasterServer);
%conn.connect("www.masterserver.com:80");
%conn.send("POST query.php Host: 127.0.0.1\r\n");
%conn.send(%postdata);
I have also heard of another method using an HTTPObject and a %obj.post function. Does anyone have any information on either methods and which one works properly? Any information on posting data to a form using the POST method would be useful, thanks.
example: (%postdata = data to post)
%conn = new TCPObject(MasterServer);
%conn.connect("www.masterserver.com:80");
%conn.send("POST query.php Host: 127.0.0.1\r\n");
%conn.send(%postdata);
I have also heard of another method using an HTTPObject and a %obj.post function. Does anyone have any information on either methods and which one works properly? Any information on posting data to a form using the POST method would be useful, thanks.
#2
06/18/2002 (2:47 pm)
Anyone want to add this to the HTML parser?
#3
06/18/2002 (2:54 pm)
does that code work (has anyone tested it, I haven't had a chance yet)?
#4
You will probably need to write an URL Encode function to properly handle the data that you will post.
06/18/2002 (2:57 pm)
I tested it the code in my Edited post does work.You will probably need to write an URL Encode function to properly handle the data that you will post.
Torque Owner Harold "LabRat" Brown
EDIT: OK this is tested and should work
%postdata="Field1=One&Field2=Two&Field3=Three";
%conn = new TCPObject(MasterServer);
%conn.connect("www.masterserver.com:80");
%conn.send("POST query.php HTTP/1.1\r\n");
%conn.send("Host: 127.0.0.1\r\n");
%conn.send("Content-type: application/x-www-form-urlencoded\r\n");
%conn.send("Content-length: " @ strlen(%postdata) @ "\r\n\r\n");
%conn.send(%postdata @ "\r\n");