It's all in the wrist...

Welcome to Baddabean.com
Tuesday, September 07 2010 @ 09:00 PM MST

Simple desktop HTTP-In

Here's a tutorial that will help show how a simple html form can be used, straight from the desktop, to communicate with your LSL scripts ;o)
  • First, you'll need a prim.

  • In this prim use this script - alter it how you want, it's pretty simple and it's mostly the script for http-in we've all seen a hundred times. If you are old like me, you may have to use Ctrl-(+) to increase the text size so you can actually read it on here.
  • 
    key requestURL;
     
    default
    {
     
        touch_start(integer num_detected) {
            requestURL = llRequestURL();     // Request that an URL be assigned to me.
        }
         http_request(key id, string method, string body) {
     
            if ((method == URL_REQUEST_GRANTED) && (id == requestURL)) {
                // An URL has been assigned to me.
                llOwnerSay(body);
                llOwnerSay("Copy and paste the above url into your html form action.");
            }
            
            else if ((method == URL_REQUEST_DENIED) && (id == requestURL)) {
                // I could not obtain a URL
                llOwnerSay("ERROR: " + body);
                requestURL = NULL_KEY;
            }
    
            else if (method == "POST") {
               llOwnerSay(body);
               
               llHTTPResponse(id,200,"Baddabean!");
            }
            
            else {
                // An incoming message has come in using a method that has not been anticipated.
                llHTTPResponse(id,405,"Unsupported Method");
            }
        }
        //use this if you have a way to update the prim url, such as an offworld file or db
        //changed(integer change) {
            //if(change & CHANGED_REGION_START) llResetScript();   
        //}
    
    }
    
  • As you can see, when it receives a POST, it will llOwnerSay the posted message to you and then respond with 'Baddabean!' Now, it's time to minimize SL and open Notepad or whatever plain text writer you have.

  • In your text file, you're going to create an html page like so:
  • 
    <html><head><title>Testing 1-2-3</title></head>
    <body>
    <form name="frmTest" method="POST" action="">
    Ask this inworld: <input type="text" size="40" name="question" value="What bean won't give you gas?" /><br />
    <input type="submit" value="Ask"></form>
    </body>
    </html>
    
  • Here, you can see it's a simple html form. First thing you'll notice is that the action is empty in the form tag. Switch back to SL, and touch your prim. You should get the prim's URL in chat. Copy the URL from chat history, jump back over to your text file and paste the URL between the quotation marks for the form action tag. Save your text file with an html extension.

  • Now, just open your new html page in your browser (double click for most) and press the submit button. You should immediately go to a page with the response 'Baddabean!' or whatever you made your script say. Jump over to SL and look in chat - you'll see the question sent from your desktop!

Have fun and remember, it's all in the wrist..

Trackback

Trackback URL for this entry: http://baddabean.com/trackback.php?id=20091030155613587

No trackback comments for this entry.
Simple desktop HTTP-In | 0 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.