URL Handler (In-Process CGI routine) that executes a GPL console command and returns the string value for use in a web page.
/console
Prerequisites
None
AJAX Send Request (XMLHttpRequest) Parameters
.Open("POST", "/console", false)
A required AJAX method that specifies the type of request, the URL, and if the request should be handled asynchronously or not. For this operation, the method must be "POST", the url must be "/console", and async must be false to synchronize the reading of the RPC results.
.SetRequestHeader("Content-type", type)
A required AJAX method that defines the format of the reply. The type should be set to "text/plain" for general compatibility.
.Send(string)
A required AJAX method that specifies the Console Command to be executed along with any required arguments. Since GPL requires double quotes around String constants, the string should contain the following fields surrounded by single quotes as follows:
'command arg1 ... argn'
where
- "command" specifies the console command to be executed.
- "arg1 … argn" is a list (possibly empty) of arguments to be passed to the command.
Remarks
This method permits standard GPL Console Commands to be issued from web pages using an HTML POST operation to the special URL named "/console". The contents of the POST are interpreted by the GPL web server as a command. One way to issue the POST is by using AJAX to issue the POST and read the response.
As compared to the aspConsole server side Javascript procedure that embeds its response text in the web page, this method permits the response to be copied to a JavaScript variable for additional processing on the client.
With regard to the response text:
- The command response is a string value. If there are multiple lines of output in response to the command, each line is separated by a line-feed character (ASCII byte value 10).
- Any output generated by Console.Write() or Console.Writeline() due to the command execution is contained in the response string.
- The final line contains the success or error response to the command. It begins with a standard GPL error number, followed by a comma, followed by the error message.
- If the command completes without error, the last line contains: 0,"Success".
DataID 464 has no effect on the remote console commands. Commands are hard-coded to time-out in 30 seconds.
Examples
Here is an example AJAX script containing the console command "show version":
var xmlHttpOprStt
function CommandTest() {
xmlHttpOprStt=new XMLHttpRequest();
xmlHttpOprStt.open("POST","/console",false);
xmlHttpOprStt.setRequestHeader("Content-type","text/plain");
xmlHttpOprStt.send('show version');
return xmlHttpOprStt.responseText
}After execution, the function returns a string containing:
Controller model G2400<lf>GPL 3.2G5, Oct 17 2012, Beta
Release<lf>RTOS-4.6.1(PowerPC/PowerPC 603e/ids5200) Apr 3
2009<lf>Configuration: RTC, Options: RTC<lf>0,"Success"<lf>where: <lf> represents the line-feed character.
See Also
Web Dictionary Summary | aspGPL| aspConsole | /rpcURL Handler