Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HttpClient.DefaultRequestHeaders | defaultRequestHeaders property

Gets a collection of headers that should be sent with each request.

Syntax


var defaultRequestHeaders = httpClient.defaultRequestHeaders;

Property value

Type: HttpRequestHeaderCollection

The headers that should be sent with each request.

Remarks

The DefaultRequestHeaders property returns an HttpRequestHeaderCollection object that can be used to get or set the specific headers on the HttpClient instance. HTTP headers set on this property will be sent on all request messages sent on this HttpClient instance and don't need to be set on each HttpRequestMessage instance.

The Headers property on the HttpRequestMessage object returns an HttpRequestHeaderCollection object that can be used to get or set the specific headers on a specific HTTP request.

The DefaultRequestHeaders property represents the headers that an app developer can set, not all of the headers that may eventually be sent with the request. The HttpBaseProtocolFilter will add some additional headers.

Warning  

In versions before Windows 10, setting certain headers to NULL caused an empty header value to be set, which caused an unexpected failure in subsequent calls to GetAsync. Starting in Windows 10, setting any of the following headers to NULL causes them to be removed from the request entirely, so that the remaining headers are valid.

  • Authorization
  • Date
  • From
  • Host
  • If-Modified-Since
  • If-Unmodified-Since
  • Max-Forwards
  • Proxy-Authorization
  • Referer

If you are writing for versions before Windows 10, do not set these header values to NULL.

 

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Web.Http
Windows::Web::Http [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Web.Http
Windows::Web::Http [C++]

Metadata

Windows.winmd

See also

HttpClient

 

 

Show: