Skip to content

HTTP

Scripts reach the outside world over HTTP. An object can call any web server, and can also act as a small web server itself with a temporary URL. Part of the Communications feature.

Concepts

Functions and events

keyllHTTPRequest(string url, list parameters, string body)
eventhttp_response(key request_id, integer status, list metadata, string body)
keyllRequestURL()
eventhttp_request(key request_id, string method, string body)
llHTTPResponse(key request_id, integer status, string body)

Scripting Details

keyllHTTPRequest(string url, list parameters, string body)
Sends an HTTP request to the specified url containing body and configured via parameters. Raises an http_response event and returns a key query handle identifying the request.
eventhttp_response(key request_id, integer status, list metadata, string body)
Triggered when an HTTP response body is received for a pending request_id, or if the request fails or times out.
stringllEscapeURL(string url)
Returns a string representing the escaped/encoded version of url, replacing spaces with '%20' and non-alphanumeric characters with their '%xx' hexadecimal UTF-8 equivalent.
stringllUnescapeURL(string url)
Returns a string representing the unescaped/decoded version of url, replacing '%20' with spaces and decoding raw UTF-8 characters.
keyllRequestURL()
Asynchronously requests one HTTP URL for use by this script, triggering an http_request event. Returns a key query handle.
keyllRequestSecureURL()
Asynchronously requests one secure HTTPS (SSL, port 12043) URL for use by this object, triggering an http_request event. Returns a key query handle.
llReleaseURL(string url)
Releases the specified url (previously obtained via llRequestURL), rendering it no longer usable.
eventhttp_request(key request_id, string method, string body)
Triggered when the script's registered URL receives an incoming HTTP request identified by request_id.
llHTTPResponse(key request_id, integer status, string body)
Responds to the incoming HTTP request identified by request_id with the HTTP status code status and the payload body.
stringllGetHTTPHeader(key request_id, string header)
Returns a string representing the value of the specified header associated with the HTTP request_id.
llSetContentType(key request_id, integer content_type)
Sets the 'Content-Type' header of subsequent HTTP server responses (via llHTTPResponse) for request_id using the specified content_type (a CONTENT_TYPE_* constant).
integerllGetFreeURLs()
Returns an integer representing the number of available HTTP URLs (remaining for the owner if the object is attached, or for the region if unattached).

An object that answers web requests with its region name.

default
{
state_entry()
{
llRequestURL();
}
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change)
{
if (change & (CHANGED_REGION | CHANGED_REGION_START)) llResetScript();
}
http_request(key id, string method, string body)
{
if (method == URL_REQUEST_GRANTED)
llOwnerSay("URL: " + body);
else if (method == "GET")
llHTTPResponse(id, 200, llGetRegionName());
else
llHTTPResponse(id, 405, "Method not allowed");
}
}

Constant groups HTTPRequestParam 10HTTPContentType 9HTTPResponseError 1

See also Feature CommunicationsCategory WebSL Wiki LSL HTTPSL Wiki HTTP Server URL RegistrationFeature Data TransmissionPlanned Guide: an object as a web server