WebClient.Headers Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets a collection of header name/value pairs associated with the request.

Namespace: System.Net
Assembly: System.Net (in System.Net.dll)


Public Property Headers As WebHeaderCollection
public WebHeaderCollection Headers { get; set; }

Property Value

Type: System.Net..::.WebHeaderCollection
A WebHeaderCollection containing header name/value pairs associated with this request.


The Headers property contains a WebHeaderCollection instance containing header information that the WebClient sends with the request. This is an unrestricted collection of headers, so setting headers that are restricted by WebRequest descendants such as HttpWebRequest is allowed.

Some headers are considered restricted and are either exposed directly (such as Content-Type) or protected by the system and cannot be set in a WebHeaderCollection object. Any attempt to set one of these restricted headers in the WebHeaderCollection object using the Item[([(HttpRequestHeader])]) or Item[([(String])]) property or throws an exception. If the WebHeaderCollection object is associated with a HttpWebRequest object, the exception is thrown by the Item[([(HttpRequestHeader])]) property. If the WebHeaderCollection object is associated with a WebClient object, the exception is thrown when an attempt to send the WebClient request occurs.

For a list of restricted headers, see the Remarks in the WebHeaderCollection class.

For security reasons, the WebClient class is restricted from sending specific headers to a cross-domain site unless the header is allowed by the security policy applicable to the target cross-domain site. This restriction applies to resources from locations other than the site of origin. The Authorization header can be set using the Headers property. However to set the credentials properly, the cross-domain policy applicable to the target must have the http-request-headers set to allow the Authorization header to be sent.

You should not assume that the header values will remain unchanged, because Web servers and caches may change or add headers to a Web request.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


WebClient Class

System.Net Namespace