Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a sample I wrote for a blog. I think the code itself pretty much explains itself. </p> <p><hr> Client Side AS3 Code :</p> <pre><code>var urlString:String = "http://localhost:1337/"; function Submit():void { var requestVars:URLVariables = new URLVariables(); requestVars.Username = "guest"; var request:URLRequest = new URLRequest(); request.url = urlString; request.method = URLRequestMethod.GET; request.data = requestVars; var loader:URLLoader = new URLLoader(); loader.dataFormat = URLLoaderDataFormat.TEXT; loader.addEventListener(Event.COMPLETE, loaderCompleteHandler); try { loader.load(request); } catch (error:Error) { // Handle Immediate Errors } } function loaderCompleteHandler(e:Event):void { trace(e.target.data); // Response Text } </code></pre> <p>Brief about the code snippet:</p> <ul> <li>We fill in the request data by instantiating a URLVariables class as <strong>requestVars</strong>.</li> <li>We fill in the url &amp; method by instantiating URLRequest class as <strong>request</strong>.</li> <li>We attach an load complete event Handler to handle the response.</li> <li>Wrapping up for catching errors, we call the load method.</li> <li><p>URL is set to Localhost port 1337 where the nodeJS would be hosted.</p></li> <li><p>The variable set is a test field UserName which is checked for in the server script.</p></li> </ul> <hr> <p>Server Side NodeJS Code :</p> <pre><code>var http = require('http'), url = require('url'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); var urlObj = url.parse(req.url, true); if(urlObj.query["Username"] == "guest") res.end("True"); else res.end("False"); }).listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/'); </code></pre> <p>Brief about the code snippet:</p> <ul> <li>The code listens at port 1337 in the localhost server where it is hosted.</li> <li>The query string is unwrapped to get the UserName variable &amp; tested.</li> <li>Server Responds with <strong>true</strong> since the value equates to <strong>guest</strong>.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload