Shymus Roffo Posted August 31, 2012 Share Posted August 31, 2012 i have been trying to figure out how to send requests with PHP into SL and it is starting to become a pain in the butt, i am not good with the function fsockopen. i have tried cURL and so far nothing is working. I do not like XML-RPC cause it needs updated every 10 minutes.the LSL scripts works when i submit a html form and open the url in my browser, but does not work when i try to send a cURL request.LSL script//I made this script simple just to see if i was able to get a request. key reqid; default { state_entry() { reqid = llRequestURL(); llOwnerSay((string)reqid); } http_request(key id, string method, string body) { if(id == reqid) { if(method == URL_REQUEST_GRANTED) llOwnerSay(body); } llOwnerSay(llGetHTTPHeader(id,"x-query-string")); llOwnerSay(llGetHTTPHeader(id,"x-script-url")); llHTTPResponse(id, 200, "Recieved"); llOwnerSay(body); } } PHP Script:<?php $ch = curl_init("http://sim9058.agni.lindenlab.com:12046/cap/5d700359-60b8-ad8a-872f-a817da37cf2f/?hello=hello"); $nvp = "&msg=hello"; curl_setopt($ch,CURLOPT_POSTFIELDS,$nvp); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); echo curl_exec($ch); ?> Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted August 31, 2012 Share Posted August 31, 2012 Before lookig at the scripts: Are you sure you can send out an http request from the port required? Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted August 31, 2012 Share Posted August 31, 2012 Here is a little test script you can use - it uses fsock <?php$url = '';//the URL of your object goes hereecho "Request answered<br>";$Data = CallLSLScript($url, "Hello this is a test");die($Data);function CallLSLScript($URL, $Data, $Timeout = 10) { echo "callscript: ".$URL."<br>"; //Parse the URL into Server, Path and Port $Host = str_ireplace("http://", "", $URL); $Path = explode("/", $Host, 2); $Host = $Path[0]; $Path = $Path[1]; $PrtSplit = explode(":", $Host); $Host = $PrtSplit[0]; $Port = $PrtSplit[1]; //Open Connection $Socket = fsockopen($Host, $Port, $Dummy1, $Dummy2, $Timeout); echo "<br>socket: ".$Socket."<br>"; if ($Socket) { //Send Header and Data fputs($Socket, "POST /$Path HTTP/1.1\r\n"); fputs($Socket, "Host: $Host\r\n"); fputs($Socket, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($Socket, "User-Agent: Opera/9.01 (Windows NT 5.1; U; en)\r\n"); fputs($Socket, "Accept-Language: de-DE,de;q=0.9,en;q=0.8\r\n"); fputs($Socket, "Content-length: ".strlen($Data)."\r\n"); fputs($Socket, "Connection: close\r\n\r\n"); fputs($Socket, $Data); //Receive Data while(!feof($Socket)) {$res .= fgets($Socket, 128);} fclose($Socket); echo "sent<br>"; } //return the data to the bowser echo $res;}?> You have to add the URL of the object in the top part of the script. Call the script from a browser - it will give you some output - the variable $res will echo the full header and body of what the response of the object returned - the actual body is at the end. Here is the LSL script that goes with it: key gkURLReq;string gsURLOut;default { state_entry() { gkURLReq = llRequestURL(); } http_request(key id, string method, string body) { if (gkURLReq == id) { gkURLReq = ""; if (method == URL_REQUEST_GRANTED) { llSay(0,"URL: " + body); gsURLOut = body; } else if (method == URL_REQUEST_DENIED) { llInstantMessage(llGetOwner(), "Something went wrong at " + llGetTimestamp() + " , no url. " + body); } } else { llOwnerSay("request received" + body); llHTTPResponse(id, 200, "This is the response from SL."); } }} Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now