Game Development Community

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.

About the author

Recent Threads

  • Using TCPObject

  • #1
    06/18/2002 (11:08 am)
    Try this. I'm not at a PC capable of running Torque at the moment so I can't test. I'll verify this code when I go home for lunch.

    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");
    #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
    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.