LSL Wiki Mirror 10-5-2006: llHTTPRequest

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
key llHTTPRequest(string url, list parameters, string body)

Sends HTTP request to url with the specified body and parameters.

url must always be a valid HTTP or HTTPS URL, pointing to a location outside the Linden Lab and Second Life servers.

parameters is a list of <integer key, string value> pairs:
parameter Default Value
HTTP_BODY_MAXLENGTH 2048 (Setting HTTP_BODY_MAXLENGTH is not yet supported)
HTTP_METHOD "GET" "GET", "POST", "PUT" and "DELETE"
HTTP_MIMETYPE "text/plain;charset=utf-8" text/* MIME types should specify a charset. To emulate HTML forms use application/x-www-form-urlencoded. This allows you to set the body to a properly escaped (llEscapeURL) sequence of <name,value> pairs in the form var=value&var2=value2 and have them automatically parsed by web frameworks (PHP will allow you to retrieve them from $_POST) (Supported in version 1.10.4)
HTTP_VERIFY_CERT TRUE If TRUE, the server SSL certificate must be verifiable using one of the standard certificate authorities when making HTTPS requests. If FALSE, any server SSL certificate will be accepted. (Supported in version 1.10.4)

body specifies the body of the HTTP request and is only used when HTTP_METHOD is POST or PUT. The body is only limited to the amount of available free memory in the script (before the script has a stack/heap collision.)

The key returned by llHTTPRequest uniquely identifies the request and is passed to the http_response() event handler along with the request results when the request completes.

HTTP requests made using llHTTPRequest are throttled based on the script owner and region. Requests are throttled to a maximum of 20 requests per 100 seconds. See this thread (or this page) and this thread (or this page) for more details.

If any errors are found in the parameters given to llHTTPRequest, or the HTTP request cannot be made as the owner has exceeded the allowed request rate, then the returned key will be set to NULL_KEY and error messages will be sent to the debug channel.

The following headers are added to HTTP requests made by llHTTPRequest:

Header Value Description
Accept text/*
Accept-Charset utf-8;q=1.0, *;q=0.5
User-Agent Second Life LSL/VERSION (http://secondlife.com/) simulator version making the request
X-SecondLife-Shard SHARD "Production" if the HTTP request is made from SL; otherwise, "Testing"
X-SecondLife-Object-Name NAME object name making the HTTP request
X-SecondLife-Object-Key KEY object UUID making the HTTP request
X-SecondLife-Region NAME(X,Y) region containing the object making the request; X,Y is its grid location
X-SecondLife-Local-Position (X,Y,Z) object region coordinates making the request
X-SecondLife-Local-Rotation (X,Y,Z, W) object quaternion rotation making the request
X-SecondLife-Local-Velocity (X,Y,Z) object velocity making the request
X-SecondLife-Owner-Name NAME object owner name making the HTTP request
X-SecondLife-Owner-Key KEY object owner key making the HTTP request
Note, some languages may export the X-SecondLife-* variables differently, however the HTTP headers send it as X-SecondLife-Shard and simular, with a ASCII hyphen, and no prefix before X, these are also not LSL constants in the variables and conform to HTTP header specifications, not LSL specifications. - Ice

This lets some very useful things be done, such as getting keys from key databases. Example, using the w-hat.com database:

//Quick hack to find and display resident's keys from the w-hat name2key database
//  Keknehv Psaltery, 5/5/06

key requestid;
string resident;

default
{
    state_entry()
    {
        llListen(1,"","","");
    }
    listen( integer chan, string name, key id, string msg )
    {
        list names = llParseString2List(msg,[" "],[]);
        resident = llDumpList2String(names," ");
        requestid = llHTTPRequest("http://w-hat.com/name2key?name="+llDumpList2String(names,"+"),[HTTP_METHOD,"GET"],"");
    }
    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == requestid)
        {
            integer i = llSubStringIndex(body,resident);
            if ( i != -1 )
                llSay(0,llGetSubString(body,i,i+llStringLength(resident)+36));
            else
                llSay(0,"No resident named \""+resident+"\" found in the w-hat name2key database");
        } else
            llSay(0,(string)status+" error");
    }
}



An example of using llHTTPRequest/http_response with your own PHP Server


Functions | Communications
There are 39 comments on this page. [Display comments/form]