llHTTPRequest
|
|
Jarod Godel
Utilitarian
Join date: 6 Nov 2003
Posts: 729
|
04-13-2006 21:52
For anyone trying to figure out llHTTPRequest on the Preview Grid, he's a small adding script I cobbled together tonight that shows off how the basics work: LSL code: string geturl = "http://profnano.org/test/math.php"; string tName; integer listenNumber; list args;
default { state_entry() { llSay(0, "Adder ready!"); }
touch_start(integer total_number) { tName = llKey2Name(llDetectedKey(0)); listenNumber = llListen(0, tName, NULL_KEY, ""); llSay(0, "Please say two numbers, and seperate them by a comma (ex: 1,2)..."); } listen(integer channel, string name, key id, string message) { llSay(0, "Thank you"); args = llParseString2List(message, [","], ["", " "]); string mathurl = geturl + "?a=" + llList2String(args, 0) + "&b=" + llList2String(args, 1); llHTTPRequest(mathurl, [HTTP_METHOD, "GET"], ""); llListenRemove(listenNumber); tName = ""; } http_response(key request_id, integer status, list metadata, string body) { integer x = llSubStringIndex(body, "<answer>") + 8; integer y = llSubStringIndex(body, "</answer>") - 1; string answer = llGetSubString(body, x, y); llSay(0, llList2String(args, 0) + " + " + llList2String(args, 1) + " = " + answer); args = []; } }
PHP code: <?php
$a = $HTTP_GET_VARS["a"]; $b = $HTTP_GET_VARS["b"]; $answer = floatval($a) + floatval($b);
$xml = '<?xml version="1.0" encoding="ISO-8859-1"?><math><answer>' . strval($answer) . '</answer></math>'; header('Content-type: text/xml'); echo($xml); ?>
People are welcome to use the URL stuck in the LSL code, it's on my server and I doubt it'll go away any time soon. Have fun!
_____________________
"All designers in SL need to be aware of the fact that there are now quite simple methods of complete texture theft in SL that are impossible to stop..." - Cristiano MidnightAd aspera per intelligentem prohibitus.
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
04-13-2006 22:55
If LL hasn't given us outgoing XML-RPC, here is a script that *should* be able to build XML-RPC requests using llHTTPRequest (assuming i didn't screw up somewhere, i haven't tested it  ). key request;
key SendRemoteData(key uuid, string StringValue, integer IntValue) { if(StringValue) StringValue = "<string>" + StringValue + "</string>"; else StringValue = "<string/>"; if(uuid != "") uuid = "<string>" + (string)uuid + "</string>"; else uuid = "<string/>"; string body = "<?xml version=\"1.0\"?><methodCall> <methodName>llRemoteData</methodName><params><param><value> <struct><member><name>Channel</name><value>"+ (string)uuid +"</value></member><member><name>IntValue</name><value><int>" + (string)IntValue + "</int></value></member><member><name>StringValue</name><value>" + StringValue + "</value></member></struct></value></param></params> </methodCall>"; return llHTTPRequest("http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi", [HTTP_METHOD, "POST"], body);//$[E10006]$[E10006]$[E10006] }
default { state_entry() { request = SendRemoteData("2d0efb26-0287-f25c-9d55-5fd09339ff14", "", 0); } http_response(key id, integer status, list headers, string body)//comment this out to make it pass though lslint // link_message(integer a, integer status, string body, key id)//and uncomment this line. { if(id == request && status == 200) { if(!llSubStringIndex(body, "<?xml version=\"1.0\"?>")) { if(llSubStringIndex(body, "<?xml version=\"1.0\"?><methodResponse><fault>")) {//a cleverly crafted (ok not so cleverly crafted) xml-rpc responce can generate an invalid xml responce. integer p = llSubStringIndex(body, "<int>"); @loop; integer m = p + 1 + llSubStringIndex(llDeleteSubString(body,0,p), "<int>"); if(m > p) { p = m; jump loop; } m = p + 1 + llSubStringIndex(llDeleteSubString(body,0,p), "</int>"); integer IntValue = (integer)llGetSubString(body, p + 5, m - 1); string StringValue = llGetSubString(body, 211, p - 53); if(StringValue == "<string/>") StringValue = ""; else StringValue = llDeleteSubString(StringValue, -9, 7); //Insert your code here llOwnerSay(llList2CSV([IntValue, StringValue])); } else ;//invalid request } else ;//some horrible error } } }
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
|
Marcus Moreau
frand
Join date: 25 Dec 2004
Posts: 602
|
04-14-2006 12:59
So some of my cohorts have found that you can overload with too many requests and get blacklisted (ie: several calls per second for several seconds). This has been confirmed. Can anyone (preferably a Linden heh) provide a stat on how much is too much? It'd be nice to know the limit so we don't all go getting blacklisted.
MM
_____________________
Marcus Moreau
Disenfranchised island owner...
"This statement is false." User #121869 or something close
|
|
Jarod Godel
Utilitarian
Join date: 6 Nov 2003
Posts: 729
|
04-14-2006 15:27
From: Marcus Moreau It'd be nice to know the limit so we don't all go getting blacklisted. I'd guess around twenty. I was tooling around with my iTunes controller last night, flipping through songs, and I got the error "Jarod Godel has used too many requests for the area in too little time" or something. (I think it'll reset if you log out and then back in, btw.) May guess is between 10-20 requests within a five minute period. That, however, is not official.
_____________________
"All designers in SL need to be aware of the fact that there are now quite simple methods of complete texture theft in SL that are impossible to stop..." - Cristiano MidnightAd aspera per intelligentem prohibitus.
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
key request_id?
04-14-2006 15:52
Looks like this implementation is incomplete, since there's no key passed to the request nor returned from it to associate a request with a response.
|
|
HeatherDawn Cohen
Who Me?!?!
Join date: 9 Aug 2004
Posts: 397
|
04-14-2006 16:00
Does anyone have some examples of what this will allow us to do? If this has anything do with me being able to set my own stuff for sale on my own website (like SLX or something) wooohooo. If not, help me understand.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
04-14-2006 16:06
Strife, What does your script do? If I understand it right, it lets one object send an XML-RPC request to the channel set up by another object? Assuming the channel UUID has been made available to the sender somehow. Does off-world XML-RPC exist, as requests going out from SL? Or maybe that's meaningless. Certainly, I can see using HTTP to trigger the scripts that I'm now triggering using email -> .forward -> procmail -> PHP. But that's off-word comms, and I'm wondering if your script is a roundabout way of achieving object-to-object comms at better-than-email speeds. Though moving my PHP scripts to the web area means I probably will have to start worrying about malformed query and other attacks, which right now I don't have to worry about, since it's triggered by email, which is slightly less public. Web security isn't my strong point at all 
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
04-14-2006 19:31
The script i posted will allow the user to create malformed requests. But SL's current implementation also lets you create malformed responces, so i see it as moot (my script shouldn't choke on malformed responces from SL). That said, yes you can use SL to make outgoing XML-RPC requests with this script, but whats the point? If you can send XML-RPC requests you can send raw requests. Parsing XML in SL is a pain (trust me). It wastes bandwidth.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
|
MadamG Zagato
means business
Join date: 17 Sep 2005
Posts: 1,402
|
04-15-2006 02:12
I put this script on my server and tried passing a querystring as you did. Nothing was happening. No response. So I hard coded a response to be sure it was working on my end. And I did get that response back in SL! Cool! So why the couldnt I pass a simple lil querystring to my webpage? I checked my server logs to see what was happening. And lo and behold the ? in my url/querystring is not being passed by SL! So is this a bug, or something that LL can turn on and off at will? http://www.yourdomain.com/mypage?message=Hello looks like this on my server logs: http://www.yourdomain.com/mypage message=Hello I made sure it wasn't just me by passing the same querystring from another page and also typing in the URL with Querystring on Google, then following the link to my page (Google is handy that way). No problem there. So it must be something LL has done, or maybe it's disabled? I dunno.
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
04-15-2006 03:10
Has anyone tried POST yet? reqkey = llHTTPRequest(URL, [HTTP_METHOD, "POST"], "said=hello"); I get the right CONTENT_LENGTH in the headers, but for some reason PHP doesn't have anything in the $_POST array. Am I missing something?
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
04-15-2006 03:51
Oh feep. Well, answered my own question. Have to use $HTTP_RAW_POST_DATA to get to it, since SL isn't setting CONTENT_TYPE to application/x-www-form-urlencoded. Which is, of course, why Strife's works. Um, any chance of getting some way to set that? 
|
|
Adam Marker
new scripter
Join date: 2 Jan 2004
Posts: 104
|
magic for secondlife.com?
04-15-2006 08:01
I was able to get the http request to work for various sites, but no luck with anything at secondlife.com. Is there some special format I need?
|
|
Sky Honey
Coder
Join date: 16 May 2005
Posts: 105
|
04-15-2006 08:14
From: someone url must always be a valid HTTP URL. HTTP requests can only be made to locations outside Linden Lab. from llHTTPRequest
|