method get

void get(string url,requestListener requestListener,object context,flags getFlags);

Argumente

Zurückgegebener Wert

This method sends an HTTP GET request to the server.

The following example shows a simple GET request, passing in a listener which will receive the response callback, and a context value which will be returned in the onResponse or onError callback.
var contextData = 1;
function main()
{
    var httpRequest = shell.serviceManager.http.request;
    var listener = new httpListener();  
    var context = new contextObject(contextData);

    httpRequest.get("http://search.aol.com", listener, context, 0);
}

function contextObject(num)
{
    this.num = num;
}

function httpListener()
{
    this.onResponse = onResponse;
    this.onError = onError;
}

function onResponse(requestor, code, text, header, payload, context)
{
    alert("The request returned code: " + code);
    alert("The status text for the return is: " + text);
  
    // the context value will match the 1 specified in the get
    alert("The context of this request is: " + context.num);

    // output the payload, to show the html for aol.com
    if (payload)
    {
        var streamReader = shell.serviceManager.basics.rawStreamReader;
        streamReader.stream = payload;
        var text = streamReader.readStringTillEndOfStream('');
        alert("The payload returned is: " + text); 
    }         

    // output a field from the returned header
    if (header)
    {
        // ** Note ** if Content-Length field does not exist, the following code will throw a JavaScript exception.        
        var headerFieldArray = header.valueForKey("Content-Length");

        // use a 0 to get the first value, because the Content-Length header field only contains one value.
        var contentLength = headerFieldArray.getValue(0);
        if (contentLength)
        {
            alert("Content Length returned is: " + contentLength);
        }   
    }
}

function onError(requestor, code, context)
{
    alert("Http error: " + code);
}