TCPObject post
by Chris Labombard · in Torque Game Builder · 10/26/2005 (12:01 pm) · 4 replies
Could someone please help me figure out what is wrong with this :
Im trying to run www.spunkygames.com/echo.php
and send it name and score.
It is returning:
yet I can run it fine in a browser... so Im assuming its the post string.
Im trying to run www.spunkygames.com/echo.php
and send it name and score.
function test()
{
$tcpserv = new TCPObject();
$tcpserv.connect("www.spunkygames.com:80");
}
function TCPObject::onConnected(%this)
{
%score = 10000;
%name = "ChrisL";
%postdata="name=" @ %name @ "&score=" @ %score;
$tcpserv.send("POST echo.php HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-type: application/x-www-form-urlencoded\r\nContent-length: " @ strlen(%postdata) @ "\r\n\r\n" @ %postdata @ "\r\n");
}
function TCPObject::onLine(%this, %line)
{
echo(%line);
}It is returning:
1c9 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <HTML><HEAD> <TITLE>400 Bad Request</TITLE> </HEAD><BODY> <H1>Bad Request</H1> Your browser sent a request that this server could not understand.<P> Invalid URI in request POST echo.php HTTP/1.1<P> <P>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. <HR> <ADDRESS>Apache/1.3.33 Server at gaspra.lunarpages.com Port 80</ADDRESS> </BODY></HTML>
yet I can run it fine in a browser... so Im assuming its the post string.
About the author
I have been a professional game programmer for over 5 years now. I've worked on virtually every platform, dozens of games and released a few of my own games, including 2 iPhone titles and a title waiting release on Big Fish Games.
#2
The slash doesnt make a difference
10/26/2005 (2:22 pm)
HTTPObject presented issues, so I used Labrat's exmaples of using TCPObject.The slash doesnt make a difference
#3
works whereas pasting:
causes the "Invalid URI in request" error to happen. The only difference being the slash. Output the string you're sending and try it manually to see what's wrong with it.
10/26/2005 (2:57 pm)
There's multiple things wrong then, as telnetting directly to the server and pasting:POST /echo.php HTTP/1.1 Host: www.spunkygames.com Content-type: application/x-www-form-urlencoded Content-length: 23 name=ChrisL&score=10000
works whereas pasting:
POST echo.php HTTP/1.1 Host: www.spunkygames.com Content-type: application/x-www-form-urlencoded Content-length: 23 name=ChrisL&score=10000
causes the "Invalid URI in request" error to happen. The only difference being the slash. Output the string you're sending and try it manually to see what's wrong with it.
#4
It works now :)
10/27/2005 (3:40 am)
Thank you Luke. The problem was that I had host set to 127.0.0.1 instead of www.spunkygames.comIt works now :)
Torque 3D Owner Luke D
Default Studio Name
Manually creating request strings can be a tricky and finicky. If you're going to be doing this through http, why not use an HTTPObject with the values as parameters on the URL?
To debug these kinds of issues, I recommend either doing a telnet to the server and typing in your request manually in order to work out any kinks, and if that fails, capture a working request from the browser by sniffing the network and compare the two.
A useful tool for getting a quick example of a request can be found at http://web-sniffer.net/