User:Opensource Obscure/http

From Second Life Wiki
Jump to navigation Jump to search

BACK to User:Opensource_Obscure

With this script, a prim requests a new LSL Server public URL, then makes a http call that updates a db with the prim's public URL.
This is probably horrible, I can't code, don't use this if you don't know what you're doing.

<lsl> default {

   state_entry()
   {

llSay(0, "clean this script!");

       llRequestURL();     
   }

   http_request(key id, string method, string body)
   {
       if (method == URL_REQUEST_GRANTED)
       {
           a = body;
           llOwnerSay("chiamo: " + url+a);
           llSetObjectDesc(a);
           http_request_id = llHTTPRequest(url+a, [HTTP_METHOD, "POST"], "");             
       }
       else if (method == URL_REQUEST_DENIED)
       {
           llOwnerSay("Something went wrong, no url. " + body);
       }
       else if (method == "GET")
       {
           string text = llGetHTTPHeader(id, "x-query-string");
           llSetText(text, <1,1,1>, 1);
           llHTTPResponse(id,200,"OK! Please click BACK in your browser");
           llSay(0, "called by web");
       }
       else
       {
           llHTTPResponse(id,405,"Unsupported Method");
       }
   }

   touch_start(integer total_number)
   {
       llOwnerSay("MY URL: " + a);
       llSetObjectDesc(a);        
       http_request_id = llHTTPRequest(url+a, [], "");           
   }


   http_response(key request_id, integer status, list metadata, string body)
   {
       if (request_id == http_request_id)
       {
           // llInstantMessage(llGetOwner(), body);
       }
   }        


}

</lsl>