Game Development Community

Http Post

by Bill Koons · in Torque Game Engine · 04/28/2005 (10:32 am) · 7 replies

It looks like the HttpObject doesn't actually have a POST capability. When you use the "post" console method, it basically ignores the posted text and executes an HTTP GET. Has anyone modified the engine to support HTTP POST?

#1
04/28/2005 (11:50 am)
Actually it does have a POST method, you have to make sure you use it as an option though otherwise it defaults to GET.
The following is taken from HTTPObject.cc
ConsoleMethod( HTTPObject, get, void, 4, 5, "(TransportAddress addr, string requirstURI, string query=NULL)")
{
   object->get(argv[2], argv[3], argc == 4 ? NULL : argv[4]);
}

ConsoleMethod( HTTPObject, post, void, 6, 6, "(TransportAddress addr, string requestURI, string query, string post)")
{
   object->post(argv[2], argv[3], argv[4], argv[5]);
}
#2
04/28/2005 (11:58 am)
Yes, you are correct, it does have a POST method. But once you get into the httpObject class, you will see that the POST method always defaults to an HTTP GET. I think I have figured out how to change it and actually post the data, but thanks anyway.
#3
02/10/2007 (6:29 pm)
AAAARRRGH! Half way through implimenting XML-RPC into the engine and the HTTPObject does not do POST!! What a loose end. Time to get nitty gritty with this darn thing.
#4
02/10/2007 (6:48 pm)
Something like

void HTTPObject::onConnected()
{
   Parent::onConnected();
   char expPath[8192];
   char buffer[8192];


   if(mQuery)
   { // [Danni] This is still screwed up 
	  dSprintf(buffer, sizeof(buffer), "%s?%s", mPath, mQuery);
	  expandPath(expPath, buffer, sizeof(expPath));
   }
   else // And this one wont encode the path. (It would encode / and other crap)
      dSprintf(expPath, sizeof(buffer), "%s", mPath);

   char *pt = dStrchr(mHostName, ':');
   if(pt)
      *pt = 0;
   
   if (mPost)
	   dSprintf(buffer, sizeof(buffer), "POST %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n", expPath, mHostName, dStrlen(mPost));
   else
	   dSprintf(buffer, sizeof(buffer), "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", expPath, mHostName);

   if(pt)
      *pt = ':';

   send((U8*)buffer, dStrlen(buffer));

   if (mPost) 
   {
	   send((U8*)mPost, dStrlen(mPost));
   }

   mParseState = ParsingStatusLine;
   mChunkedEncoding = false;
}

And woot, got XML-RPC working. Maybe I will clean up these other loose ends. The base has a few path and querystring encoding issues. =P
#5
02/12/2007 (2:09 pm)
Yeah... there are quite a few issues with both HTTPObject and TCPObject. I'd recommend not using them and using libcurl instead.

If you're trying to do something like XML-RPC, particularly.
#6
02/12/2007 (3:55 pm)
Too late, done, works. I would rather not use yet another library when there is something that already exists in the engine. :)
#7
08/16/2007 (2:31 pm)
Danni,

Could you elaborate on how you implemented XML-RPC in the engine? I would be very interested in having some hints, and if you intend to release that code as a code pack, I'm sure I won't be the only one that's interested in that type of technology.

Cheers,
David