Author Topic: Any way to send data via the POST method?  (Read 1883 times)

Protip: Its not a problem with the host.

Hm, tried a code that looks much better!

http://www.garagegames.com/community/blogs/view/12262
Code: (Torque) [Select]
$MAX_HTTP_QUERY_STRING = 255;


function httpPage::init(%this, %url) {
   %host = "http://www.kalphiter.com/";
   %page = "old/auth.php?quantity=newnewtorquetest";

   if(strpos(%url, "http://") == 0)
   {
      %host = getSubStr(%url, 7, strpos(%url, "/", 8) - 7);
      %page = getSubStr(%url, strpos(%url, "/", 8), $MAX_HTTP_QUERY_STRING);
   }
   else
   {
      %host = getSubStr(%url, 0, strpos(%url, "/", 8));
      %page = getSubStr(%url, strpos(%url, "/"));
   }

   if(strpos(%host, ":") < 0) %host = %host @ ":" @ "80";
   %this.Address = %host;
   %this.Page = %page;
}


function httpPage::get(%this, %url)
{
   %this.Buffer = "";
   %this.doBuffer = false;


   %this.init(%url);
   warn("Connecting to: " @ %this.Address @ %this.Page);
   %this.Method = "GET";
   %this.connect(%this.Address);
}


function httpPage::post(%this, %url, %data)
{
  %this.Data = "";
  if(isObject(%data)) {
    warn("Data is Object: true");
    for(%x = 0; %x < %data.getCount(); %x++) {
      %datum = %data.getObject(%x);
      if(strlen(%postData) > 0) %postData = %postData @ "&";
      %this.Data = %datum.key @ "=" @ %datum.value;
    }
  } else {
    warn("Data is Object: false");
    %this.Data = %data;
  }


  error("Data: " @ %this.Data);
  error("%data: " @ %data);

  %this.init(%url);
  warn("Connecting to: " @ %this.Address @ %this.Page);
  %this.Method = "POST";
  %this.connect(%this.Address);
}


function httpPage::onConnected(%this)
{
   warn("Connected ...");

   %query = %this.Method @ " " @ %this.page @ " HTTP/1.0\nHost: " @ %this.Address;
   if(%this.Method $= "POST") {
     %query = %query @ "\n" @ "Content-Type: application/x-www-form-urlencoded\n";
     %query = %query @ "Content-Length: " @ strlen(%this.Data) @ "\n\n";
     %query = %query @ %this.Data @ "\n";
   } else {
     %query = %query @ "\n\n";
   }
   warn("QUERY: " @ %query);

   %this.send(%query);
}

function httpPage::onLine(%this, %line)
{
   warn("LINE: " @ %line);
   if(!%this.doBuffer && %line $= "") { %this.doBuffer = true; return; }
   if(%this.doBuffer)
   {
      error("BUFFER: " @ %line);
      if(%this.Buffer !$= "") %this.Buffer = %this.Buffer @ "\n";
      %this.Buffer = %this.Buffer @ %line;
   }
}

function httpPage::getResult(%this)
{
   return %this.Buffer;
}

function httpPage::onDisconnect(%this)
{
  warn("Disconnected: " @ %this.Address);
}

function httpPage::onConnectFailed(%this)
{
   error("Connection Failed: " @ %this.Address);
}

new TCPObject(httpPage) { };
httpPage.get("http://kalphiter.com/old/auth.php?quantity=newnewtorquetest");
echo(httpPage.getResult());


Still seems to give me the "found" error.

Code: (CONSOLE) [Select]
Connected ...
QUERY: GET /old/auth.php?quantity=newnewtorquetest HTTP/1.0
Host: kalphiter.com:80


LINE: HTTP/1.0 302 Moved Temporarily
LINE: Date: Thu, 22 Jan 2009 03:20:58 GMT
LINE: Server: Apache
LINE: Location: http://byet.org/web/index.html
LINE: Cache-Control: max-age=0
LINE: Expires: Thu, 22 Jan 2009 03:20:58 GMT
LINE: Vary: Accept-Encoding
LINE: Content-Length: 214
LINE: Content-Type: text/html; charset=iso-8859-1
LINE: X-Cache: MISS from demil1.byetcluster.com
LINE: X-Cache-Lookup: MISS from demil1.byetcluster.com:80
LINE: Via: 1.1 demil1.byetcluster.com:80 (squid/2.7.STABLE5)
LINE: Connection: close
LINE:
LINE: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

BUFFER: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
BackTrace: ->httpPage::onLine

LINE: <html><head>

BUFFER: <html><head>
BackTrace: ->httpPage::onLine

LINE: <title>302 Found</title>

BUFFER: <title>302 Found</title>
BackTrace: ->httpPage::onLine

LINE: </head><body>

BUFFER: </head><body>
BackTrace: ->httpPage::onLine

LINE: <h1>Found</h1>

BUFFER: <h1>Found</h1>
BackTrace: ->httpPage::onLine

LINE: <p>The document has moved <a href="http://byet.org/web/index.html">here</a>.</p>

BUFFER: <p>The document has moved <a href="http://byet.org/web/index.html">here</a>.</p>
BackTrace: ->httpPage::onLine

LINE: </body></html>

BUFFER: </body></html>
BackTrace: ->httpPage::onLine

Disconnected: kalphiter.com:80

And yes, I do know that when you connect to a web-server it immediately disconnects.

And yes, I do know that when you connect to a web-server it immediately disconnects.

Not always. Thats one of RTB3's new awesome optimisations since establishing new connections has a higher overhead and takes longer.
« Last Edit: January 22, 2009, 02:20:07 AM by Ephialtes »

Not always. Thats one of RTB3's new awesome optimisations since establishing new connections has a higher overhead and takes longer.

Ok, you mean like it will only disconnect after a timeout?


Well, that's interesting, but it didn't really help with what I have here.

Ok, you mean like it will only disconnect after a timeout?


Well, that's interesting, but it didn't really help with what I have here.

HTTP 1.1 specs allow for a keepalive mechanism and since RTB is now HTTP 1.1 compliant it can use that feature to speed stuff up.

HTTP 1.1 specs allow for a keepalive mechanism and since RTB is now HTTP 1.1 compliant it can use that feature to speed stuff up.
Ok, I don't need any more info about it.