Skip to main content

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.

ReturnHeaders()

Returns a string containing the main HTTP headers in this request.

OutputHeaders()

Writes the main HTTP headers to the current device.

GetHeader()

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

SetHeader()

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:

  1. The name of the header (not case-sensitive), without the colon (:) delimiter; this is a string such as Host or Date

  2. 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.

FeedbackOpens in a new tab