Blockland Forums > Modification Help
TCPObject::get(%this) Resource
<< < (2/2)
Lugnut:

--- Quote from: Port on March 09, 2012, 05:18:43 PM --- I don't quite see the point in an entire resource and thread just for this. Writing HTTP requests is already so laughably easy.

--- End quote ---
Sorry port, we're not all quite as skilled as you.
I'll definitely learn from this.
Fluff-is-back:
As Kalphiter stated, HTTP Objects are just as useful for GET requests, and even simpler to use that TCP Objects:


function getWebPage(%host, %port, %file) // For example, if we wanted to get the page "example.com:80/file.ext", then we would use getWebPage("example.com", 80, "/file.ext")
{
    new HTTPObject(MyHTTPObject).get(%host @ ":" @ %port, %file); // Creating the HTTPObject and sending a request to example.com:80/file.ext
}

// Now we need to process the response
// Unlike TCPObjects, HTTPObjects do not return any headers
function MyHTTPObject::onLine(%this, %line)
{
    %page = %page NL %line; // For each new line we add the data onto a single variable
    if(%line $= "END") // You can have a line on the page, such as 'END' that tells the client to do something, in this case, run a function with the gathered data
    {
        doStuffWith(%page);
        %this.disconnect();
        %this.delete();
    }
}


Alternatively, you can use the HTTPObject::onDisconnect method to let the script know the data is complete.
Navigation
Message Index
Previous page

Go to full version