Author Topic: HTTPObject  (Read 1276 times)

I'm using httpobjects to try and interact with PHP on my site. However, I'm having trouble sending multiple variables ($_GET['bla']). Whenever I send more than one parameters, they sort of lump together.

I want to do:
mysite.com/bla.php?var1=please&var2=work

Instead, there is no var2 and var1 is equal to "please&var2=work".

Any ideas?

Yep, that's torque's stuffty HTTP object implementation.
Use a TCP object and configure the HTTP packets yourself.

Ok. If you happen to have any TCP object tutorials that are nice and easy to follow, link me up.

Otherwise I'll be searchin'

Thanks.

As I've said in the past, use RTB as a reference. It has extensive usage of TCPObjects.

Allright. I'll take a look at it, thanks.

EDIT: Took a peek... A stuffload of .cs files! Any specific ones I should check out? I'm cntrl-Fing TCP but it's not coming up with anything so far.
DBLEDIT: Found some TCP in the IRC file... nvm
« Last Edit: March 12, 2011, 01:02:52 AM by cucumberdude »

Code: [Select]
new TCPObject(cucumber) {
   host = "mysite.com:80";
};
function cucumber::sendRequest(%this, %request) {
   %this.request = %request SPC "HTTP/1.0\r\nHost:" SPC getSubStr(%this.host, 0, strPos(%this.host, ":")) @ "\r\nConnection: close\r\n\r\n";
   %this.connect(%this.host);
}
function cucumber::onConnected(%this) {
   if(strLen(%req = %this.request) < 1) {
      %this.disconnect();
      return;
   }
   %this.request = "";
   %this.send(%req);
}
function cucumber::onLine(%this, %line) {
   // stuff
}
function cucumber::onDisconnect(%this) {
   // stuff
}

cucumber.sendRequest("GET /bla.php?var1=please&var2=work");

Client networking with TCPObject
function TCPObject::onDNSResolved(%this)
function TCPObject::onDNSFailed(%this)
function TCPObject::onConnected(%this)
function TCPObject::onConnectFailed(%this)
function TCPObject::onDisconnect(%this)
function TCPObject::onLine(%this,%line)
TCPObject.connect("host:port");
TCPObject.send("packet");
Simple HTTP request
Code: [Select]
$url = "www.google.com";
$port = 80;
$file = "/search";
$args = "?q=dog";
new TCPObject(Google);
function googleIt(%query)
{
$args = "?q=" @ urlEnc(%query);
Google.connect($url @ ":" @ $port);
}
function Google::onConnected(%this)
{
%this.send("GET " @ $file @ $args @ " HTTP/1.0\r\nHost: " @ $url @ "\r\nUser-Agent: Torque/1.0\r\n\r\n");
}
function Google::onLine(%this,%line)
{
echo("RECEIVED LINE: " @ %line);
}

Thanks guys, got it working.

Only problem is I get some gibberish about the server before the content.

Code: [Select]
HTTP/1.1 200 OK
Date: Sat, 12 Mar 2011 05:45:33 GMT
Server: Apache
X-Powered-By: PHP/5.2.16
Connection: close
Content-Type: text/html

How do I get rid of that?

Thanks guys, got it working.

Only problem is I get some gibberish about the server before the content.

Code: [Select]
HTTP/1.1 200 OK
Date: Sat, 12 Mar 2011 05:45:33 GMT
Server: Apache
X-Powered-By: PHP/5.2.16
Connection: close
Content-Type: text/html

How do I get rid of that?
Both Ephialtes and Badspot do this.

HTTP/1.1 200 OK
Date: Sat, 12 Mar 2011 05:45:33 GMT
Server: Apache
X-Powered-By: PHP/5.2.16
Connection: close
Content-Type: text/html

START
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
information/tinformation/tinformation/tinformation
END


The only record what's between START and END.

view-source:http://master2.blockland.us/

Oh duh, just tailor PHP output.

Thanks.

Is there a content-length value? You can work it out from that.
Otherwise you'll just need to add all your data you want to process like so:

PHP
Code: [Select]
echo "SOMEMESSAGE\tThe value of this message is this.";
Torque
Code: [Select]
if(getField(%line,0) $= "SOMEMESSAGE")
        echo(getField(%line,1); //should echo "The value of the message is this."
EDIT: nvm use Iban's method

If you don't have access to modifying google.com, and still don't want the headers, you can do something like:
Code: [Select]
function tcp::onLine(%this, %line) {
   if(!%this.header && strLen(trim(%line)) < 1)
      %this.header = true;
   else if(%this.header) {
      here's your data, without the header
   }
}
Remember to set .header to false if you reconnect or something.