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.) (As of 10/29/06 this seems to be limited to 2048 characters, and
cuts off anything further - Seifert)
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.
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.
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 location
|
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
This
lets some very useful things be done, such as getting keys from key databases.
Example, using the w-hat.com database:
//Quick hack to find and display resident's keys from the w-hat name2key database
// Keknehv Psaltery, 5/5/06
key requestid;
string resident;
default
{
state_entry()
{
llListen(1,"","","");
}
listen( integer chan, string name, key id, string msg )
{
list names = llParseString2List(msg,[" "],[]);
resident = llDumpList2String(names," ");
requestid = llHTTPRequest("http://w-hat.com/name2key?name="+llDumpList2String(names,"+"),[HTTP_METHOD,"GET"],"");
}
http_response(key request_id, integer status, list metadata, string body)
{
if (request_id == requestid)
{
integer i = llSubStringIndex(body,resident);
if ( i != -1 )
llSay(0,llGetSubString(body,i,i+llStringLength(resident)+36));
else
llSay(0,"No resident named \""+resident+"\" found in the w-hat name2key database");
} else
llSay(0,(string)status+" error");
}
}
Note: Requests currently come
from
64.129.40.0/23
66.150.244.0/23
69.25.104.0/23
72.5.12.0/22
Source
An
example of using llHTTPRequest/http_response with your own PHP
Server
Functions | Communications