Template:Needs Translation/
函数名
|
Function: string llGetHTTPHeader( key request_id, string header )
|
参数:
- key request_id–A valid HTTP request key.
- string header–Lower case header value name.
|
返回值:返回一个字符串,该字符串是request_id的头的值。
|
注意事项
|
注意事项
- 在30秒后或者调用llHTTPResponse后,头信息将无法访问。
- 不支持自定义标头,只支持规范中列出的标头。
- LSL不是一个CGI环境
- “Content-Type”是一个普通标题名的例子,在CGI环境中,名称应该是“HTTP_CONTENT_TYPE”。
- 标题必须是小写的(否则它将不匹配任何内容)。所有头名称在接收时都转换成小写。
- 当提出请求时…
- URL的路径部分必须以正斜杠作为前缀
- 为了使用查询字符串,必须包含一个路径(即使只是一个斜杠)
|
示例
|
key url_request;
default
{
state_entry()
{
url_request = llRequestURL();
}
http_request(key id, string method, string body)
{
if (url_request == id)
{
// if you're usually not resetting the query ID
// now is a good time to start!
url_request = "";
if (method == URL_REQUEST_GRANTED)
{
llOwnerSay("URL: " + body);
key owner = llGetOwner();
vector ownerSize = llGetAgentSize(owner);
if (ownerSize)// != ZERO_VECTOR
llLoadURL(owner, "I got a new URL!", body);
}
else if (method == URL_REQUEST_DENIED)
llOwnerSay("Something went wrong, no url:\n" + body);
}
else
{
list headerList = ["x-script-url",
"x-path-info", "x-query-string",
"x-remote-ip", "user-agent"];
integer index = -llGetListLength(headerList);
do
{
string header = llList2String(headerList, index);
llOwnerSay(header + ": " + llGetHTTPHeader(id, header));
}
while (++index);
llOwnerSay("body:\n" + body);
llHTTPResponse(id, 200, body);
}
}
}
|