Template:Needs Translation/
函数名
|
Function: llReleaseURL( string url );
|
参数:string url - URL释放
|
返回值:释放指定的URL,它将不再可用。
|
注意事项
|
url在某些情况下会自动释放并失效。在下列情况下,不需要调用llReleaseURL。但是之后你得申请一个新的
当该区域重新启动或脱机时
当包含url的脚本被重置或重新编译时
当包含脚本的对象被删除或进入目录时
|
示例
|
重要:永远不要忘记再次发布你所请求的URL !url和prims一样是区域资源。如果你把他们都带走了,你就会和sim所有者或地产经理陷入大麻烦。
string url;
key urlRequestId;
key selfCheckRequestId;
request_url()
{
llReleaseURL(url);
url = "";
llSetTimerEvent(0.0);
urlRequestId = llRequestURL();
}
throw_exception(string inputString)
{
llInstantMessage(llGetOwner(), inputString);
// 是的,重新启动是处理异常的坏方法.
// 然而,这只是一个演示脚本…
llResetScript();
}
default
{
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change)
{
if (change & CHANGED_OWNER | CHANGED_REGION | CHANGED_REGION_START)
llResetScript();
}
state_entry()
{
request_url();
}
http_request(key id, string method, string body)
{
integer responseStatus = 400;
string responseBody = "Unsupported method";
if (method == URL_REQUEST_DENIED)
throw_exception("The following error occurred while attempting to get a free URL for this device:\n \n" + body);
else if (method == URL_REQUEST_GRANTED)
{
url = body;
llLoadURL(llGetOwner(), "Click to visit my URL!", url);
// 每5分钟检查一次丢失的URL
llSetTimerEvent(300.0);
}
else if (method == "GET")
{
responseStatus = 200;
responseBody = "Hello world!";
}
// else if (method == "POST") ...;
// else if (method == "PUT") ...;
// else if (method == "DELETE") { responseStatus = 403; responseBody = "forbidden"; }
llHTTPResponse(id, responseStatus, responseBody);
}
http_response(key id, integer status, list metaData, string body)
{
if (id == selfCheckRequestId)
{
// 如果你不经常这样做,现在是习惯这样做的好时机!
selfCheckRequestId = NULL_KEY;
if (status != 200)
request_url();
}
else if (id == NULL_KEY)
throw_exception("Too many HTTP requests too fast!");
}
timer()
{
selfCheckRequestId = llHTTPRequest(url,
[HTTP_METHOD, "GET",
HTTP_VERBOSE_THROTTLE, FALSE,
HTTP_BODY_MAXLENGTH, 16384],
"");
}
}
|