SetHeader Method  
 

Set the value of a request header field.

Syntax

object.SetHeader HeaderField, HeaderValue

Parameters

HeaderField
A string that specifies the name of the request header field.
HeaderValue
A string that specifies the value associated with the given header field. If this argument is set to an empty string, the field is deleted from the request header.

Return Value

This method returns a Boolean value. If the method succeeds, it will return True. If the header field cannot be created or modified, it will return False.

Remarks

The SetHeader method is used to set the values of specific fields in the HTTP request header. This method should be called before the client has requested the resource. Some headers are automatically generated by methods that send resource requests. Some of these are supplied by the requesting methods only if the application has not previously defined the header. For others, the requesting method overrides what the application may have defined. The affected headers include:

  • The Accept header value is generated with a value of */* for most requests unless it has already been assigned. This tells the server that the client will accept all content types. Changing this header may cause requests to fail if the resource does not return a data type that matches the specified value.
  • The Authorization header value is generated automatically if authentication has been specified. Applications should not modify this header value directly, set the UserName and Password properties instead.
  • The Connection header value is generated in accordance with the settings of the KeepAlive property and the version of the HTTP protocol being used. This header is not used with HTTP 1.0 connections that do not support persistent client sessions.
  • The Content-Length header value is generated automatically for POST and PUT requests. Applications should not modify this header value directly.
  • The Content-Type header value is generated with a value of application/x-www-form-urlencoded for POST requests unless the EncodingProperty has been set to prevent URL-encoding of data. If a file is being uploaded using the PUT method, the header value is set according to the type of data that is being sent to the server. Applications should not modify this header value directly.
  • The Host header value is assigned the host name of the server that was specified when the connection was established. It is not recommended that applications change this header value because it may yield unexpected results on servers that use virtual hosting.
  • The Proxy-Authorization header value is generated for proxy connections which a username and password has been specified. Applications should not modify this header value directly, set the ProxyUser and ProxyPassword properties instead.

See Also

HeaderField Property, HeaderValue Property, GetFirstHeader Method, GetHeader Method, GetNextHeader Method