Don't click here unless you want to be banned.

LSL Wiki : llHTTPRequest

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org
key llHTTPRequest(string url, list parameters, string body)

Sends HTTP request to url with the specified body and parameters.

url must always be a valid HTTP or HTTPS URL, pointing to a location outside the Linden Lab and Second Life servers.

parameters is a list of <integer key, string value> pairs:
parameter 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 (PHP will allow you to retrieve them from $_POST) (Supported in version 1.10.4)
HTTP_BODY_MAXLENGTH 2 integer 2048 (Setting HTTP_BODY_MAXLENGTH is not yet supported)
HTTP_VERIFY_CERT 3 integer 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. (Supported in version 1.10.4)

Although the HTTP_AUTHORIZATION parameter is not available, you may still login to websites requiring basic authentication by formatting your url appropriately:
string username = "Your Name";
string password = "Your Password";
string url = "http://" + llEscapeURL(username) + ":" + llEscapeURL(password) + "@domain.com/page.php";

body specifies the body of the HTTP request and is only used when HTTP_METHOD is POST or PUT. The body is only limited to the amount of available free memory in the script (before the script has a stack/heap collision.)
By my testing on 2009-02-19, the above statement is correct. The request is limited only by memory. The response is cut off at 2KB. Anyone wishing to read the old debate here, review the page history. -- Siann Beck

The key returned by llHTTPRequest uniquely identifies the request and is passed to the http_response() event handler along with the request results when the request completes.

Attention: Having more than one http_response handler (2 scripts) gives you confusing results. I haven't digged into that deeply but I got responses coming out in the "wrong" response handler. So checking the keys of the response is a good idea. Maybe you should avoid having several handlers at all. (06/03/2008, CynthiaCentaur)

HTTP requests made using llHTTPRequest are throttled based on the script owner and region. Requests are throttled to a maximum of 20 requests per 100 seconds. See this thread (or this page) and this thread (or this page) for more details.
NOTE: This has been changed to 100 requests per 100 seconds now...
NOTE: This is changed again: Requests are throttled on a per object basis. 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.
SL Wiki post

If any errors are found in the parameters given to llHTTPRequest, or the HTTP request cannot be made as the owner has exceeded the allowed request rate, then the returned key will be set to NULL_KEY and error messages will be sent to the debug channel.

The following headers are added to HTTP requests made by llHTTPRequest:

Header Value Description
Accept text/*
Accept-Charset utf-8;q=1.0, *;q=0.5
User-Agent Second Life LSL/VERSION (http://secondlife.com/) simulator version making the request
X-SecondLife-Shard SHARD "Production" if the HTTP request is made from SL; otherwise, "Testing"
X-SecondLife-Object-Name NAME object name making the HTTP request
X-SecondLife-Object-Key KEY object UUID making the HTTP request
X-SecondLife-Region NAME(X,Y) region containing the object making the request; X,Y is its grid GlobalCoordinate note that for the SL MapAPI you have to divide this value by 256 to get the Sim south-west corner, to get center divide by 256 then add 0.5
X-SecondLife-Local-Position (X,Y,Z) object region coordinates making the request
X-SecondLife-Local-Rotation (X,Y,Z, W) object quaternion rotation making the request
X-SecondLife-Local-Velocity (X,Y,Z) object velocity making the request
X-SecondLife-Owner-Name NAME object owner name making the HTTP request This will be group if the object is deeded to group
X-SecondLife-Owner-Key KEY object owner key making the HTTP request This will be group if the object is deeded to group
Note, some languages may export the X-SecondLife-* variables differently, however the HTTP headers send it as X-SecondLife-Shard and similar, with an ASCII hyphen, and no prefix before X; these are also not LSL constants in the variables and conform to HTTP header specifications, not LSL specifications. - Ice

Most CGI languages and some more general languages that can be used with HTTP servers will convert the headers into HTTP_X_SECONDLIFE_* and this can be expected as a known behavior, Python, cgi-bin based programs and some others use this, this is a language specific trait, and not how the sim sends them. - Ice

For example, a call to
llHTTPRequest("http://example.com:9999/test", [HTTP_METHOD, "POST"], "foo\nbar");
results in the following HTTP request:
POST /test HTTP/1.0
Host: example.com:9999
Pragma: no-cache
Accept-Encoding: deflate, gzip
Accept: text/*
Accept-Charset: utf-8;q=1.0, *;q=0.5
Content-Type: text/plain;charset=utf-8
User-Agent: Second Life LSL/1.18.6(77554) (http://secondlife.com)
X-SecondLife-Shard: Production
X-SecondLife-Object-Name: Object
X-SecondLife-Object-Key: 1fff0a02-3783-af23-60cd-d7aca39f2391
X-SecondLife-Region: Stillman (256512, 256512)
X-SecondLife-Local-Position: (51.301704, 81.737869, 256.500000)
X-SecondLife-Local-Rotation: (0.000000, 0.000000, 0.000000, 1.000000)
X-SecondLife-Local-Velocity: (0.000000, 0.000000, 0.000000)
X-SecondLife-Owner-Name: Ezhar Fairlight
X-SecondLife-Owner-Key: 8121c2f3-4a88-4c33-9899-8fc1273f47ee
Content-Length: 7
Via: 1.1 sim3057.agni.lindenlab.com:3128 (squid/2.5.STABLE9)
X-Forwarded-For: 127.0.0.1
Cache-Control: max-age=259200
Connection: keep-alive

foo
bar

This lets some very useful things be done, such as getting keys from key databases. Example, using the w-hat.com database:

// To make looking up keys with a script easier, if you add terse=1  to the URL, the response will contain only the key you asked for.
// If it was not found, it will return NULL_KEY. Example script:
string NAME  = "Masakazu Kojima";           // name to look up
string URL   = "http://w-hat.com/name2key"; // name2key url
key    reqid;                               // http request id

default {
    state_entry() {
        reqid = llHTTPRequest( URL + "?terse=1&name=" +
                               llEscapeURL(NAME), [], "" );
    }

    http_response(key id, integer status, list meta, string body) {
        if ( id != reqid )
            return;
        if ( status == 499 )
            llOwnerSay("name2key request timed out");
        else if ( status != 200 )
            llOwnerSay("the internet exploded!!");
        else if ( (key)body == NULL_KEY )
            llOwnerSay("No key found for " + NAME);
        else
            llOwnerSay(NAME + "'s key is: " + body );
    }
}

The following example does the same as the above using the EXL name2key database, which offers many more advanced features and a web interface:

// ----------------------------------------------------------------------
// Licensing
// ----------------------------------------------------------------------
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//  
//  �2009 [EXL]
//  Program & service maintained by:
//      Charlotte Wirtanen
//      Hg Beeks
// ----------------------------------------------------------------------


// ----------------------------------------------------------------------
// Internal constants, do not change.
// ----------------------------------------------------------------------
string NAME2KEY_SINGLE  = "fetch";
string NAME2KEY_WILD    = "fetch_wild";
string NAME2KEY_FULL    = "fetch_full";
// ----------------------------------------------------------------------

key exlName2Key(string name, string method)
// Returns a request id and triggers an http_response, where body is the agent key
// string name = agent name to search for
// string method = NAME2KEY_SINGLE, NAME2KEY_WILD or NAME2KEY_FULL
//
//  NAME2KEY_SINGLE = Returns a single result key
//  NAME2KEY_WILD   = Returns a 2-stride list of all possible matching
//      names and their respective keys, with a limit of 30 results and
//      using the % (percentage) character as a wild card.
//  NAME2KEY_FULL   = Returns a list with the following structure:
//      result[0] = agent name
//      result[1] = agent key
//      result[2] = agent last seen date in unix timestamp format
//      result[3] = agent or monitor that spotted this person last
//      result[4] = region coordinates where agent was last seen
//      result[5] = local region position where agent was last seen
//      NAME2KEY_FULL is limited to 1 user, no wildcards.
{
    return llHTTPRequest(
        "http://www.balseraph.org/name2key.php/" + method + "/" + llEscapeURL(name), 
        [], ""
    );
}

// ----------------------------------------------------------------------
// Function callbacks - Your code goes here.
// ----------------------------------------------------------------------
exlSingleName2KeyCallback(string result, key request_id)
// Called when the http_response completes successfully for NAME2KEY_SINGLE
// string result = key located from your search, NULL_KEY if not found
// key request_id = request id from completed search
{
    // ----------------------------------------------------------------------
    // TO-DO: Replace with your own result code.
    // ----------------------------------------------------------------------
    llOwnerSay("\nRequest ID " + (string)request_id + "\nReturned key: " + result);
}

exlWildName2KeyCallback(list result, integer results, key request_id)
// Called when the http_response completes successfully for NAME2KEY_WILD
// list result = 2-stride length list containing all possible matches
// integer results = total number of results found
// key request_id = request id from completed search
{
    // ----------------------------------------------------------------------
    // TO-DO: Replace with your own result code.
    // ----------------------------------------------------------------------
    llOwnerSay(
        "\nRequest ID " + (string)request_id + "\n" +
        "Returned " + (string)results + " keys: \n" + 
        llDumpList2String(result, "\n")
    );
}

exlFullName2KeyCallback(list result, key request_id)
// Called when the http_response completes successfully for NAME2KEY_FULL
// list result = 
//      result[0] = agent name
//      result[1] = agent key
//      result[2] = agent last seen date in unix timestamp format
//      result[3] = agent or monitor that spotted this person last
//      result[4] = region coordinates where agent was last seen
//      result[5] = local region position where agent was last seen
// key request_id = request id from completed search
{
    // ----------------------------------------------------------------------
    // TO-DO: Replace with your own result code.
    // ----------------------------------------------------------------------
    llOwnerSay(
        "\nRequest ID " + (string)request_id + "\n" +
        "Returned data: \n\n" + 
        "Name: " + llList2String(result, 0) + "\n" +
        "Key: " + llList2String(result, 1) + "\n" +
        "Last seen: " + llList2String(result, 2) + "\n" +
        "Seen by: " + llList2String(result, 3) + "\n" +
        "Region seen at: " + llList2String(result, 4) + "\n" +
        "Position of recorder: " + llList2String(result, 5) + "\n"
    );
}
// ----------------------------------------------------------------------

key gRequestID = NULL_KEY;

default
{
    state_entry()
    {
        // ----------------------------------------------------------------------
        // Call exlName2Key(string, method) and store the request id in a global
        // for request-matching later in http_response
        // TO-DO: Replace with your own query code.
        // ----------------------------------------------------------------------
        
        // Single search for 'Charlotte Wirtanen':
        gRequestID = exlName2Key("Charlotte Wirtanen", NAME2KEY_SINGLE);
        
        // Wildcard search for all names with 'ch' (case insensitive) in them:
        // gRequestID = exlName2Key("%ch%", NAME2KEY_WILD);
        
        // Full data search for 'Charlotte Wirtanen':
        // gRequestID = exlName2Key("Charlotte Wirtanen", NAME2KEY_FULL);
    }

    // ----------------------------------------------------------------------
    // Response callback routing - Do not edit.
    // ----------------------------------------------------------------------
    http_response(key request_id, integer status, list metadata, string body)
    {
        // Check that our request_id matches the request id we recorded from
        // calling exlName2Key(string)
        if (request_id == gRequestID)
        {
            // Fail and return in the case of our
            // http request timing out.
            if (status == 499)
            {
                llOwnerSay("Request timed out.");
                return;
            }

            // If the http status doesn't indicate success,
            // fail and return with the status code.
            if (status != 200)
            {
                llOwnerSay("Error: Status " + (string)status);
                return;
            }

            // Trim our response.
            body = llStringTrim(body, STRING_TRIM);

            // Return with an error message if the response
            // body is empty.
            if (body == "")
            {
                llOwnerSay("Empty result returned.");
                return;
            }

            // Return with an error message if an error string
            // is found.
            if (llSubStringIndex(body, "FATAL_ERROR") != -1)
            {
                llOwnerSay(body);
                return;
            }
            
            if (llSubStringIndex(body, ";") != -1)
            {
                // Trigger callback for full data query.
                exlFullName2KeyCallback(
                    llParseString2List(body, [";"], []), 
                    request_id
                );
            }
            else if (llSubStringIndex(body, ",") != -1)
            {
                // Trigger callback for multiple query.
                exlWildName2KeyCallback(
                    llCSV2List(body), 
                    llGetListLength(llCSV2List(body)) / 2, 
                    request_id
                );
            }
            else 
            {
                // Trigger callback for a single query.
                exlSingleName2KeyCallback(body, request_id);
            }
        }
    }
    // ----------------------------------------------------------------------
    // ----------------------------------------------------------------------
}


Status/error 499 is returned when there is any space in the URL. So make sure it is replaced with %20 else
the script will just return status 499 and not open any connection at all.
- Christophe003Carter

Which is why you should escape all URLs with llEscapeURL before calling this function - MurrayMint

Source


An example of using llHTTPRequest/http_response with your own PHP Server


This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | Communications Jasa SEO Murah Jasa SEO Jasa Google Adwords Jasa Adwords Google Adwords Sepatu Safety Sepatu Futsal Cheapes Hostgator Coupon Link Booking Televisori offerte Notebook Offerte Govr Edo Ziedo Portatile Apple RDAnet Lorks Karikatur Bisnis Modal Kecil Bisnis UKM Berita Terbaru Iklan Baris Jasa SEO Murah SEO Indonesia Konsultan SEO SEO Belajar SEO Penumbuh Rambut Kursus SEO Jam Tangan Casio Grosir Baju Bisnis Online Kerupuk Kulit Social Bookmark Kumpulan Puisi WBC Wonogiri Penumbuh Rambut Jam Tangan Murah Jam Tangan Murah Jam Tangan Casio Penumbuh Rambut Kerupuk Kulit Alat Kantor Laku.com Belanja Online Grosir Eceran Murah dan Aman Jasa SEO Model Jilbab Fine Tableware Permanent Hair Removal island investment development professional makeup artist bali private villa sewa mobil jakarta murah Jual rumah Jakarta Contact Lens Technology
There are 56 comments on this page. [Display comments/form]