HttpRequestHeaderCollection.Host HttpRequestHeaderCollection.Host HttpRequestHeaderCollection.Host HttpRequestHeaderCollection.Host HttpRequestHeaderCollection.Host Property

Definition

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

public : HostName Host { get; set; }
HostName Host();

void Host(HostName host);
public HostName Host { get; set; }
Public ReadWrite Property Host As HostName
var hostName = httpRequestHeaderCollection.host;
httpRequestHeaderCollection.host = hostName;

Property Value

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());
    }

See also