Opened 2 years ago

#350 new task

code snippets learned from communication scripts -- http and xml serving

Reported by: Fred T. Hamster Owned by:
Priority: minor Milestone:
Component: huffware Version:
Keywords: Cc:

Description

learned from communic scripts



request from user to load a web page:
llLoadURL(llDetectedKey(0), "Visit A Fresh Cup", "http://afreshcup.com");


load a web page's contents (two steps):
get the loading started: http_key = llHTTPRequest(url_to_load, [ ] ,"");
respond to the loaded data:

http_response(key id,integer status, list meta, string body)
{

if(http_key == id) { do stuff; }

}


serve xml to outside world:

key chan_id; global.
llOpenRemoteDataChannel();
... later...
remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
{

if (type == REMOTE_DATA_CHANNEL) {

channel opened...
chan_id = channel;
set up for processing requests maybe.

} else if (type == REMOTE_DATA_REQUEST) {

server is being asked for data.
llRemoteDataReply(channel, message_id, reply_string, reply_int);

we always need to send a reply.

}


LSL HTTP POST Example, originally by Dirty McLean?, June 30, 2006, Use freely!

default {

state_entry() {

replace this url with your own
string url = "http://mysite.com/myscript.php";
set params to [] for GET requests
list params = [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"];
set the body to your list of variables separated by semicolons
string body = "var1=test1&var2=test2";
llHTTPRequest(url, params, body);

}
http_response(key query, integer status, list meta, string body) {

string page_title;
list split = llParseString2List(body,["<title>", "</title>"],[]);
if (llGetListLength(split) > 1) page_title = llList2String(split,1);
else page_title = "unknown";
iterate through received lines...
list lines = llParseString2List(body,["\r\n", "\r", "\n"],[]);
integer i;
integer len = llGetListLength(lines);
for (i = 0; i<len; i+) llOwnerSay(llList2String(lines,i));

}

}


Change History (0)

Note: See TracTickets for help on using tickets.