Difference between revisions of "User:Opensource Obscure/http"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 5: Line 5:


<lsl>
<lsl>
string a;
string b; // NOT NEEDED
key http_request_id;
string url = "http://....php?q="; // PHP PAGE TO MANAGE DB
default
default
{
{
     state_entry()
     state_entry()
     {
     {
llSay(0, "clean this script!");
         llRequestURL();     
         llRequestURL();     
     }
     }
Line 22: Line 18:
         {
         {
             a = body;
             a = body;
             llOwnerSay("MY URL: " + a);
             llOwnerSay("chiamo: " + url+a);
             http_request_id = llHTTPRequest(url+a, [], "");             
            llSetObjectDesc(a);
             http_request_id = llHTTPRequest(url+a, [HTTP_METHOD, "POST"], "");             
         }
         }
         else if (method == URL_REQUEST_DENIED)
         else if (method == URL_REQUEST_DENIED)
Line 31: Line 28:
         else if (method == "GET")
         else if (method == "GET")
         {
         {
             llHTTPResponse(id,200,"Hello World!");
             string text = llGetHTTPHeader(id, "x-query-string");
             b = llGetHTTPHeader(id, "user-agent"); // NOT NEEDED
             llSetText(text, <1,1,1>, 1);
             llOwnerSay("USER AGENT: " + b);       // NOT NEEDED
            llHTTPResponse(id,200,"OK! Please click BACK in your browser");
             llSay(0, "called by web");
         }
         }
         else
         else
Line 40: Line 38:
         }
         }
     }
     }
 
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
         llOwnerSay("MY URL: " + a);
         llOwnerSay("MY URL: " + a);
        llSetObjectDesc(a);       
         http_request_id = llHTTPRequest(url+a, [], "");           
         http_request_id = llHTTPRequest(url+a, [], "");           
     }
     }
   
 
     http_response(key request_id, integer status, list metadata, string body)
     http_response(key request_id, integer status, list metadata, string body)
     {
     {
         if (request_id == http_request_id)
         if (request_id == http_request_id)
         {
         {
             llInstantMessage(llGetOwner(), body);
             // llInstantMessage(llGetOwner(), body);
         }
         }
     }         
     }         
 
 
}
}


</lsl>
</lsl>

Revision as of 15:25, 22 February 2009

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>