JSHttpRequest


The HttpRequest is a subclass of JSHttpMessage, and inherits all the properties and methods of its base class. In addition, the HttpRequest has the following properties:

Properties

cookies

An array of JSReqCookie objects. The array may be referenced by name (returns the value of the first cookie with that name), or by index (returns a JSReqCookie object). A new cookie can be created by assigning a string to a nonexistent name. This property may also be read or written as a string, in which case it returns the contents of the Cookie headers.

params

An array of JSParam objects.

paramType

The type of parameters in the request. This can be set to one of three values:
  • QUERY - A GET request with no body parameters.
  • multipart/form-data - A POST request with body parameters encoded using the multipart/form-data content type.
  • www-form-urlencoded - A POST request with body parameters encoded using the application/x-www-form-urlencoded content type.
Assigning to this property will cause the appropriate changes to be made to the request.

action

The request action (the action is the entire path, query and fragment parts of the request).

method

The method used (e.g. GET, POST, HEAD, etc.)

path

The request path.

query

The request query (everything after the '?' in the action path)

protocol

The request protocol (e.g. HTTP/1.1)

Example

// Set the cookie named CookieName to have
// value CookieValue (create it if does not exist) req.cookies["CookieName"] = "CookieValue";
// Set the first cookie to have name CookieName and value CookieValue
req.cookies[0] = "CookieName=CookieValue";

if (req.cookies.length > 0) {
// Print the name of the first cookie
alert("The name of the first cookie is " + req.cookies[0].name);
}
req.param["ParamName"] = "ParamValue";
// Set the first request to have name "ParamName" and value "ParamValue" // If it did not exist, it will be created (with default values for the other
// properties
req.params[0]="ParamName=ParamValue";
// Make the first parameter a body parameter
req.params[0].location = "BODY";
// Change the request to multipart/form-data
req.paramType = "multipart/form-data";