Windows Dev Center

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.

HttpRequestHeaderCollection.Host | host property

Gets or sets the HostName that represents the value of a Host HTTP header on an HTTP request.

Syntax


var host = httpRequestHeaderCollection.host;
httpRequestHeaderCollection.host = host;

Property value

Type: HostName

The HostName that represents the value of a Host HTTP header on an HTTP request. A null value means that the header is absent.

Remarks

The following sample code shows a method to set the Host header on an HttpRequestMessage object using the Host property on the HttpRequestHeaderCollection object.


    public void DemonstrateHeaderRequestHost() {
        var request = new HttpRequestMessage();

        // This is not typically set with a string.

        // Set the header with a strong type.
        // HostName is in the Windows.Networking namespace.
        var value = new Windows.Networking.HostName("example.com");
        request.Headers.Host = value;

        // Get the strong type out
        System.Diagnostics.Debug.WriteLine("Canonical Host name: {0}", request.Headers.Host.CanonicalName);

        // The ToString() is useful for diagnostics, too.
        System.Diagnostics.Debug.WriteLine("The Host ToString() results: {0}", request.Headers.Host.ToString());
    }


Requirements (Windows 10 device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Web.Http.Headers
Windows::Web::Http::Headers [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.Headers
Windows::Web::Http::Headers [C++]

Metadata

Windows.winmd

See also

HostName
HttpRequestHeaderCollection
HttpRequestMessage
HttpRequestMessage.Headers

 

 

Show:
© 2015 Microsoft