Difference between revisions of "LlHTTPResponse"

From Second Life Wiki
Jump to navigation Jump to search
m (added a comment)
m (changed example script to Void's version)
Line 17: Line 17:
|examples=
|examples=
<lsl>
<lsl>
key url_request;
string url;


default
default
{
{
    changed(integer change)
    {
        if (change & (CHANGED_REGION_START | CHANGED_REGION | CHANGED_TELEPORT))
            llResetScript();
    }
     state_entry()
     state_entry()
     {
     {
         url_request = llRequestURL();
         llRequestURL();
    }
 
    touch_start(integer num_detected)
    {
    //  PUBLIC_CHANNEL has the integer value 0
        if (url != "")
            llSay(PUBLIC_CHANNEL, "URL: " + url);
     }
     }


     http_request(key id, string method, string body)
     http_request(key id, string method, string body)
     {
     {
         if (url_request == id)
    //  http://en.wikipedia.org/wiki/Create,_read,_update_and_delete
         list CRUDmethods = ["GET", "POST", "PUT", "DELETE"];
    //  it's bit-wise NOT ( ~ ) !!!
        integer isAllowedMethod = ~llListFindList(CRUDmethods, [method]);
 
        if (isAllowedMethod)
        {
            llHTTPResponse(id, 200, "Body of request below:\n" + body);
        }
        else if (method == URL_REQUEST_GRANTED)
         {
         {
         //  if you're usually not resetting the query ID
         //  don't forget the trailing slash
        //  now is a good time to start!
             url = body + "/";
             url_request = "";


             if (method == URL_REQUEST_GRANTED)
             llOwnerSay("URL: " + url);
                llOwnerSay("URL: " + body);
 
            else if (method == URL_REQUEST_DENIED)
                llOwnerSay("Something went wrong, no URL.\n" + body);
         }
         }
         else
         else if (method == URL_REQUEST_DENIED)
         {
         {
             llHTTPResponse(id, 200, "Body of request below:\n" + body);
             llOwnerSay("Something went wrong, no URL.\n" + body);
         }
         }
     }
     }

Revision as of 09:56, 22 October 2012

Summary

Function: llHTTPResponse( key request_id, integer status, string body );

Responds to request_id with status and body.

• key request_id A valid HTTP request key.
• integer status HTTP Status (200, 400, 404, etc)
• string body Contents of the response.

The response need not be made inside the http_request event but if it does not happen in a timely fashion the request will time out (within 25 seconds).

Caveats

  • This call must be made by the script containing the http_request event where the request_id was received.
  • There is no limit, other than script size, to the amount of data that can be sent by this function.
    • llHTTPRequest can truncate the response length in receiving scripts. Be aware when using them together for prim-to-prim communications.
  • Returns 'content-type: text/plain' by default. Use llSetContentType to optionally return 'text/html' if being viewed by the object owner within a Second Life client.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> string url;

default {

   changed(integer change)
   {
if (change & (CHANGED_REGION_START

See Also

Events

•  http_request

Functions

•  llGetFreeURLs
•  llRequestURL
•  llRequestSecureURL
•  llReleaseURL
•  llGetHTTPHeader
•  llSetContentType

Articles

•  LSL http server

Deep Notes

History

All Issues

~ Search JIRA for related Issues
   llHTTPImageResponse() - function for sending image data as a response to an HTTP request

Signature

function void llHTTPResponse( key request_id, integer status, string body );