LlHTTPResponse

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

Template:Needs Translation/


函数名
Function: llHTTPResponse( key request_id, integer status, string body );
参数:

key request_id – A valid HTTP request key. integer status – HTTP Status (200, 400, 404, etc) string body – Contents of the response.

返回值:用 status 和 body 响应 request _ id。
注意事项
*This call must be made by the script containing the http_request event where the request_id was received.
  • 除了脚本大小之外,这个函数可以发送的数据量没有限制。
在接收脚本时,llhttprequest 可以截断响应长度。在使用它们进行 prim-to-prim 通信时要注意。
  • 默认的响应是“ content-type: text/plain”。使用 llsetcontenttype 可以选择返回不同的类型,如“ text/html”。
示例
示例一
string url;
 
default
{
    changed(integer change)
    {
        if (change & (CHANGED_REGION_START|CHANGED_REGION | CHANGED_TELEPORT))
            llResetScript();
    }
 
    state_entry()
    {
        llRequestURL();
    }
 
    touch_start(integer num_detected)
    {
    //  PUBLIC_CHANNEL has the integer value 0
        if (url != "")
            llSay(PUBLIC_CHANNEL, "URL: " + url);
    }
 
    http_request(key id, string method, string body)
    {
    //  http://en.wikipedia.org/wiki/Create,_read,_update_and_delete
        list CRUDmethods = ["GET", "POST", "PUT", "DELETE"];
    //  it's bit-wise NOT ( ~ ) !!!
        integer isAllowedMethod = ~llListFindList(CRUDmethods, [method]);
 
        if (isAllowedMethod)
        {
            llHTTPResponse(id, 200, "Body of request below:\n" + body);
        }
        else if (method == URL_REQUEST_GRANTED)
        {
        //  don't forget the trailing slash
            url = body + "/";
 
            llOwnerSay("URL: " + url);
        }
        else if (method == URL_REQUEST_DENIED)
        {
            llOwnerSay("Something went wrong, no URL.\n" + body);
        }
        else
        {
            llOwnerSay("Ummm... I have no idea what SL just did. Method=\""+method+"\"\n" + body);
        }
    }
}
相关函数
llGetFreeURLs

llRequestURL llRequestSecureURL llReleaseURL llGetHTTPHeader llSetConteneType

相关事件
http request

http response