Skip to main content

Examining the Request

When the CSP server responds to an HTTP request, it packages information about the incoming request into the %request object, which is available on all CSP pages. This variable is an instance of %CSP.RequestOpens in a new tab.

Note that the CSP pages also have access to the %session object, which you can use to pass additional data from page to page.

URL

To find the URL (not including the query string) of an incoming HTTP request, use the URL property of the %request object:

 Write "URL: ", %request.URL

URL Parameters

A URL may contain a list of parameters (also known as the URL query). The %request object makes these available via its Data property.

For example, suppose the incoming URL contains:

/csp/user/MyPage.csp?A=10&a=20&B=30&B=40

You can retrieve these parameters on the server using:

 Write %request.Data("A",1)    // this is 10
 Write %request.Data("a",1)    // this is 20
 Write %request.Data("B",1)    // this is 30
 Write %request.Data("B",2)    // this is 40

Data is a multidimensional property and each value stored within it has 2 subscripts: the name of the parameter and the index number of the parameter (parameters can occur multiple times within a URL as with B above). Note that parameter names are case-sensitive.

Also note that it does not matter if an incoming HTTP request is a GET or a POST request: the Data property represents the parameter values in exactly the same way.

You can use the ObjectScript $Data function to test if a given parameter value is defined:

 If ($Data(%request.Data("parm",1))) {
 }

If you wish to refer to a parameter but are not sure if it is defined, you can use the ObjectScript $Get function:

 Write $Get(%request.Data("parm",1))

You can find out how many values are defined for a particular parameter name using the Count method of the %request object:

 For i = 1:1:%request.Count("parm") {
    Write %request.Data("parm",i)
 }

The same techniques also work even when the parameter values are encrypted.

Form Data

When the CSP server receives a form submit request, it places all name/value pairs into the multidimensional Data property of the %request object, where the subscripts of Data are the names.

For example, if the form looks like this:

<form name="edit" method="post" action="GCSP.EncryptPage3.cls">
<p>Value A: <input type="text" name="inputA"></p>
<p>Value B: <input type="text" name="inputB"></p>
<p><input type="submit" value="Submit This" ></p>
</form>

Then on the server, use this to get the values of the Value A and Value B inputs:

 set myvalueA=$GET(%request.Data("inputA",1))
 set myvalueB=$GET(%request.Data("inputB",1))

If InterSystems IRIS receives a value that is longer than the string length limit, it automatically creates a stream (an instance of %CSP.CharacterStreamOpens in a new tab), writes the value to that stream, and places the stream OREF into the Data property in place of the actual value. This means that in any case where you might receive a very long string, your code should examine the value to see if it is an OREF, and then handle it accordingly:

 Set value=%request.Data("fieldname",1)
 If $isobject(value) { 
   ; Treat this as a stream 
 } Else { 
   ; Treat this as a regular string
 }

CGI Variables

The web server provides a set of values, referred to as CGI (Common Gateway Interface) environment variables, which contain information about the HTTP client and web server. You can get access to these CGI environment values using the multidimensional property CgiEnvs%request object. You can use this in the same manner as the Data property.

For example, to determine what type of browser is making the HTTP request, look at the value of the CGI environment variable HTTP_USER_AGENT:

 Write %request.CgiEnvs("HTTP_USER_AGENT")

For information on the available CGI environment variables, see CGI Environment Variables.

MIME Data

An incoming request may contain MIME (Multipurpose Internet Mail Extensions) data. This is typically used for larger pieces of information, such as files. You can retrieve MIME data using the using the multidimensional property MimeData of the %request object.

FeedbackOpens in a new tab