Skip to main content

Handling HTTP Request Parameters

Handling HTTP Request Parameters

When you send an HTTP request (see Sending the HTTP Request), you can include parameters in the location argument; for example: "/test.html?PARAM=%25VALUE" sets PARAM equal to %VALUE.

You can also use the following methods to control how your instance of %Net.HttpRequestOpens in a new tab handles parameters:

InsertParam()
method InsertParam(name As %String, value As %String)

Inserts a parameter into the request. This method takes two string arguments: the name of the parameter and the value of the parameter. For example:

 do req.InsertParam("arg1","1")

You can insert more than one value for a given parameter. If you do so, the values receive subscripts starting with 1. Within other methods, you use these subscripts to refer to the intended value.

DeleteParam()
method DeleteParam(name As %String, index As %Integer = "") as %Boolean

Deletes a parameter from the request. The first argument is the name of the parameter. The second argument is the subscript for the value to delete; use this only if the request contains multiple values for the same parameter.

CountParam()
method CountParam(name As %String) as %Integer

Counts the number of values that are associated with a given parameter.

GetParam()
method GetParam(name As %String, default As %String = "", index As %Integer = 1) as %String

Gets the value of a given parameter in the request. The first argument is the name of the parameter. The second argument is the default value to return if the request does not have a parameter with this name; the initial value for this default is the null value. The third argument is the subscript for the value to get; use this only if the request contains multiple values for the same parameter.

IsParamDefined()
method IsParamDefined(name As %String, index As %Integer = 1) as %Boolean

Checks whether a given parameter is defined. This method returns true if the parameter has a value. The arguments are the same as for DeleteParam().

NextParam()
method NextParam(name As %String) as %String

Retrieves the name of the next parameter, if any, after sorting the parameter names via $Order().

ReturnParams()
method ReturnParams() as %String

Returns the list of parameters in this request.

For details, see the class documentation for %Net.HttpRequestOpens in a new tab.

FeedbackOpens in a new tab