Author Topic: TorqueScript HTTP Request  (Read 1120 times)

Does anyone know how to make an HTTP request in TorqueScript? I want to store the content of a webpage to a variable. Thanks.

This is not really an easy topic. If you know what you're doing, RTB's source has extensive usage of the TCPObject. If I get the willpower I'll go more in depth, but that's your best bet unless someone wants to walk you through it.

I wanted to do this awhile back and never figured out how.

I could be wrong but I belive the orginal City Rp that Jookia made, also uses that sort of system. Could be worng though.

I could be wrong but I belive the orginal City Rp that Jookia made, also uses that sort of system. Could be worng though.
You're so wrong it's not even funny.

Ok, well its funny to me. Must be thinking of a diffrent thing.

If you just want a basic request:

new httpObject(example);
function example::onLine(%this, %line) {
    cancel(%this.finished);
    %this.page = %this.page @ %line NL "";
    %this.finished = %this.schedule(250, finished);
}
function example::finished(%this) {
    %this.disconnect();
    echo(%this.page);
}

...

example.get("blockland.us:80", "/");


Added the 'finished' thing for websites that don't feel like disconnecting you.

If you want something more advanced, header control, working multiple-PHP-arguments, etc, use TCPObjects.

Added the 'finished' thing for websites that don't feel like disconnecting you.

That's a pretty bad idea. You should be sending a "Connection: close" header to make sure the server knows to close the connection once output is done.

If you want something more advanced, header control, working multiple-PHP-arguments, etc, use TCPObjects.

I'd say wanting to be sure a connection terminates after data's been received would fall under "advanced" instead of just hacking it up like that. That hack won't even ensure you get all the data from a page. I wouldn't recommend using it.