Setting and Getting HTTP Headers
Setting and Getting HTTP Headers
You can set values for and get values of the HTTP headers.
Each of the following properties of %Net.HttpRequestOpens in a new tab contains the value of the HTTP header that has the corresponding name. These properties are automatically calculated if you do not set them:
-
Authorization
-
ContentEncoding
-
ContentLength (This property is read-only.)
-
ContentType (Specifies the Internet media typeOpens in a new tab (MIME type) of the Content-Type header.)
-
ContentCharset (Specifies the charset part of the Content-Type header. If you set this, you must first set the ContentType property.)
-
Date
-
From
-
IfModifiedSince
-
Pragma
-
ProxyAuthorization
-
Referer
-
UserAgent
The %Net.HttpRequestOpens in a new tab class provides general methods that you can use to set and get the main HTTP headers. These methods ignore Content-Type and other entity headers.
method ReturnHeaders() as %String
Returns a string containing the main HTTP headers in this request.
method OutputHeaders() as %Status
Writes the main HTTP headers to the current device.
method GetHeader(name As %String) as %StringA
Returns the current value for any main HTTP header that has been set in this request. This method takes one argument, the name of the header (not case-sensitive); this is a string such as Host or Date
method SetHeader(name As %String, value As %String) as %Status
Sets the value of a header. Typically you use this to set nonstandard headers; most of the usual headers are set via properties such as Date. This method takes two arguments:
-
The name of the header (not case-sensitive), without the colon (:) delimiter; this is a string such as Host or Date
-
The value of that header
You cannot use this method to set entity headers or read-only headers (Content-Length and Connection).
For details, see the class documentation for %Net.HttpRequestOpens in a new tab.