LlRequestSecureURL

来自人工智能助力教育知识百科
跳转至: 导航搜索

Template:Needs Translation/


函数名
Function: key llRequestSecureURL( );
参数:
返回值:请求一个HTTPS:// (SSL) url以供此对象使用。http_request事件与请求的结果相关联。HTTPS-in 使用端口12043。

返回一个handle (a key),用于识别http_request事件中的请求结果。

注意事项
HTTPS-in 使用端口12043。

当(重新)启动一个区域时,所有HTTP server URL都会自动释放并失效。

 使用CHANGED_REGION_START检测,这样就可以请求新的URL。
示例
重要:永远不要忘记再次发布你所请求的URL !url和prims一样是区域资源。如果你把他们都带走了,你就会和sim所有者或地产经理陷入大麻烦

请求安全URL。

string secureUrl;
key urlRequestId;
key selfCheckRequestId;
 
request_secure_url()
{
    llReleaseURL(secureUrl);
    secureUrl = "";
 
    urlRequestId = llRequestSecureURL();
}
 
throw_exception(string inputString)
{
    key owner = llGetOwner();
    llInstantMessage(owner, inputString);
 
    //是的,重新启动是处理异常的坏方法。
    //然而,这只是一个演示脚本…
 
    llResetScript();
}
 
default
{
    on_rez(integer start_param)
    {
        llResetScript();
    }
 
    changed(integer change)
    {
        if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
        {
            llReleaseURL(secureUrl);
            secureUrl = "";
 
            llResetScript();
        }
 
        if (change & (CHANGED_REGION | CHANGED_REGION_START | CHANGED_TELEPORT))
            request_secure_url();
    }
 
    state_entry()
    {
        request_secure_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)
        {
            secureUrl = body;
            key owner = llGetOwner();
            llLoadURL(owner, "Click to visit my URL!", secureUrl);
 
            //每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_secure_url();
        }
 
        else if (id == NULL_KEY)
            throw_exception("Too many HTTP requests too fast!");
    }
 
    timer()
    {
        selfCheckRequestId = llHTTPRequest(secureUrl,
                                [HTTP_METHOD, "GET",
                                    HTTP_VERBOSE_THROTTLE, FALSE,
                                    HTTP_BODY_MAXLENGTH, 16384],
                                "");
    }
}
相关函数
llGetHTTPHeader

llHTTPResponse

llReleaseURL

llGetFreeURLs

llRequestURL

相关事件