LlHTTPRequest
From Second Life Wiki
LSL Portal | | | Functions | | | Events | | | Types | | | Operators | | | Constants | | | Flow Control | | | Script Library | | | Tutorials |
Contents |
Description
Function: key llHTTPRequest( string url, list parameters, string body );230 | Function ID |
0.0 | Delay |
10.0 | Energy |
Sends an HTTP request to the specified URL with the body of the request and
parameters.
Returns a key that is a handle identifying the HTTP request
made.
• string | url | – | A valid HTTP/HTTPS URL. | |
• list | parameters | – | configuration parameters, specified as HTTP_* flag-value pairs [ parameter1, value1, parameter2, value2, . . . parameterN, valueN] |
|
• string | body | – | Contents of the request. |
Flag | Value Type | Default | Description | |
---|---|---|---|---|
HTTP_METHOD | 0 | string | "GET" | 'GET', 'POST', 'PUT' and 'DELETE' |
HTTP_MIMETYPE | 1 | string | "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 |
HTTP_BODY_MAXLENGTH | 2 | integer | 2048 | Setting HTTP_BODY_MAXLENGTH is not yet supported |
HTTP_VERIFY_CERT | 3 | integer boolean | 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. |
Header | Description | Example data | ||
---|---|---|---|---|
X-SecondLife-Shard | The environment the object is in. "Production" is the main grid and "Testing" is the preview grid | Production | ||
X-SecondLife-Object-Name | The name of the object containing the script | Object | ||
X-SecondLife-Object-Key | The key of the object containing the script | 01234567-89ab-cdef-0123-456789abcdef | ||
X-SecondLife-Region | The name of the region the object is in, along with the global coordinates of the region's south-west corner | Jin Ho (264448, 233984) | ||
X-SecondLife-Local-Position | The position of the object within the region | (173.009827, 75.551231, 60.950001) | ||
X-SecondLife-Local-Rotation | The rotation of the object containing the script | 0.000000, 0.000000, 0.000000, 1.000000 | ||
X-SecondLife-Local-Velocity | The velocity of the object | 0.000000, 0.000000, 0.000000 | ||
X-SecondLife-Owner-Name | Name of the owner of the object | Zeb Wyler | ||
X-SecondLife-Owner-Key | UUID of the owner of the object | 01234567-89ab-cdef-0123-456789abcdef | ||
CGI environments may place the headers into variables by capitalizing the entire name, replacing dashes with underscores, and prefixing the name with "HTTP_", e.g. "X-SecondLife-Object-Name" becomes "HTTP_X_SECONDLIFE_OBJECT_NAME". |
Caveats
- If there is a space in url, the http_response status code will be 499.
- The response body is limited to 2048 bytes; if it is longer it will be truncated.
- Requests are throttled on a per object basis (not per prim).
- Requests are throttled to a maximum of 25 requests per 20 seconds. This
is to support a sustained rate of 1 per second or a burst of up to 25.
- See this thread and this thread for more details.
- Requests are throttled to a maximum of 25 requests per 20 seconds. This
is to support a sustained rate of 1 per second or a burst of up to 25.
- Cannot be used to load textures or images from the internet, for more information see Web Textures.
- If the accessed site is relying on the LSL script to report L$ transactions, then it must check the X-SecondLife-Shard header to see if the script is running on the beta grid.
- Some servers will return a 405 error if you send POST to a file that can't accept metadata, such as a text or HTML file. Make sure you use the GET method to ensure success in any environment.
Examples
key http_request_id; default { state_entry() { http_request_id = llHTTPRequest("url", [], ""); } http_response(key request_id, integer status, list metadata, string body) { if (request_id == http_request_id) { llSetText(body, <0,0,1>, 1); } } }
Example PHP test script:
<?php header("content-type: text/plain; charset=utf-8"); ?> Headers received: <?php /** * @author Wouter Hobble * @copyright 2008 */ foreach ($_SERVER as $k => $v) { if( substr($k, 0, 5) == 'HTTP_') { print "\n". $k. "\t". $v; } } ?>
example wrapper script Both capturing apache headers and global methodes
<?PHP // Author Waster Skronski. // General Public License (GPL). // Mind that some headers are not included becouse they either useless or unreliable. $USE_APACHE_HEADERS = TRUE; // switch to false if you need cgi methode if ($USE_APACHE_HEADERS) { $headers = apache_request_headers(); $objectgrid = $headers["X-SecondLife-Shard"]; $objectname = $headers["X-SecondLife-Object-Name"]; $objectkey = $headers["X-SecondLife-Object-Key"]; $objectpos = $headers["X-SecondLife-Local-Position"]; $ownerkey = $headers["X-SecondLife-Owner-Key"]; $ownername = $headers["X-SecondLife-Owner-Name"]; $regiondata = $headers["X-SecondLife-Region"]; $regiontmp = explode ("(",$regiondata); // cut cords off $regionpos = explode (")",$regiontmp[1]); // $regionname = substr($regiontmp[0],0,-1); // cut last space from simname } else { $db = $GLOBALS; $headers = $db['HTTP_ENV_VARS']; $objectgrid = $headers["HTTP_X_SECONDLIFE_SHARD"]; $objectname = $headers["HTTP_X_SECONDLIFE_OBJECT_NAME"]; $objectkey = $headers["HTTP_X_SECONDLIFE_OBJECT_KEY"]; $ownerkey = $headers["HTTP_X_SECONDLIFE_OWNER_KEY"]; $objectpos = $headers["HTTP_X_SECONDLIFE_LOCAL_POSITION"]; $ownername = $headers["HTTP_X_SECONDLIFE_OWNER_NAME"]; $regiondata = $headers["HTTP_X_SECONDLIFE_REGION"]; $regiontmp = explode ("(",$regiondata); $regionpos = explode (")",$regiontmp[1]); $regionname = substr($regiontmp[0],0,-1); } ?>
Notes
If for some reason while using llHTTPRequest/http_response you are unable to parse a known good RSS feed or some other form of web contents, you will need to work around it outside of SecondLife. This is unlikely to change in the near future since checking the headers requires more overhead at the simulator level.
CGI environments may place the headers into variables by capitalizing the entire name, replacing dashes with underscores, and prefixing the name with "HTTP_", e.g. "HTTP_X_SECONDLIFE_OBJECT_NAME".
Apache can include the headers in its logs, using the CustomLog and LogFormat directives. See the docs for details on the syntax.