Script Samples

Simple Snippets

Log a message

MeddlerObject.Log.LogString("Got request for: " + oSession.requestHeaders.Path);

Read a request header

if (oSession.ReadRequest())
{
    var s: String = oSession.oRequest["HeaderName"];
}

Load a file into a byte array

var arrStartWith = Utilities.FileToByteArray("filename.dat", false);
// fuzz / Manipulate arrStartWith here...
// …
oSession.WriteBytes(arrStartWith);

Examine the request URL and use a QueryString parameter

if (oSession.ReadRequest())
{        
  if (oSession.urlContains("longpoll.cgi"))
  {
    var oSleep = oSession.GetQueryParams()["sleep"];
    if (oSleep != "undefined")
    {
      System.Threading.Thread.Sleep(Int32.Parse(oSleep));
    }

    oHeaders["Content-Type"] = "text/plain";    
    oSession.WriteString(oHeaders);
    oSession.WriteString("Response. Session ID #" + oSession.id + ", delayed by " + oSleep + "ms.");
    } else // show a different page...
//...
}

MSDN JScript.NET Reference

Page tags: script
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution 3.0 License