OsRequestURL

From OpenSimulator

Jump to: navigation, search
key osRequestURL(list options)
Requests one HTTP:// url (opensim version 0.9 or over)

Option supported : "allowXss" - Add 'Access-Control-Allow-Origin: *' to response header

Threat Level Moderate
Permissions No permissions specified
Extra Delay 0 seconds
Example(s)
//
//osRequestURL example
//
 
RequestReceived (key id, string query) {
    llHTTPResponse (id,200,query+" OK");
    query = llUnescapeURL(query);
    llSay (0, query);
}
 
default {
 
    state_entry() {
        osRequestURL ([ "allowXss" ]);
    }
 
    http_request(key id, string method, string body) {
 
        if (method == URL_REQUEST_GRANTED)
           llOwnerSay ("URL_REQUEST_GRANTED" +"\n" +body);
 
        if (method == URL_REQUEST_DENIED)
            llOwnerSay ("URL_REQUEST_DENIED");
 
        if (method == "GET")
            RequestReceived (id, llGetHTTPHeader(id,"x-query-string"));
 
        if (method == "POST")
            RequestReceived (id, body);
    }
 
}
/* Respond to incoming HTTP requests
Description: 
    This script demonstrates handling HTTP requests in OpenSimulator. 
    It provides a simple web server that responds to GET and POST requests and logs the received data.
Usage:
    Attach this script to an in-world object in OpenSimulator.
    When the object is rezzed and initialized, it will request permissions for handling HTTP requests using osRequestURL.
    The script listens for incoming HTTP requests, and when a request is received, 
    it logs whether the request was granted or denied, 
    and it processes GET and POST requests by calling the RequestReceived function.
    The RequestReceived function sends a response to the client with a status code of 200 (OK) 
    and logs the received data in local chat. It also decodes URL-encoded data using llUnescapeURL.
    You can monitor the HTTP request handling in the local chat of the object, as specified in the llOwnerSay calls.
*/
RequestReceived(key id, string query) {
    llHTTPResponse(id, 200, query + " OK"); // Send a response
    query = llUnescapeURL(query); // Decode URL-encoded data
    llSay(0, query); // Log the received data to local chat
}
 
default {
    state_entry() {
        osRequestURL(["allowXss"]); // Request permissions for handling HTTP requests
    }
 
    // Handle incoming HTTP requests
    http_request(key id, string method, string body) {
        if (method == URL_REQUEST_GRANTED)
            llOwnerSay("URL_REQUEST_GRANTED\n" + body); // Log URL_REQUEST_GRANTED
 
        if (method == URL_REQUEST_DENIED)
            llOwnerSay("URL_REQUEST_DENIED"); // Log URL_REQUEST_DENIED
 
        if (method == "GET")
            RequestReceived(id, llGetHTTPHeader(id, "x-query-string")); // Process GET requests
 
        if (method == "POST")
            RequestReceived(id, body); // Process POST requests
    }
}
Notes
This function was added in 0.9.0-post-fixes
Personal tools
General
About This Wiki