इसके माध्यम से साझा किया गया


HttpRequestHeaderCollection.Host Property

Definition

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

public:
 property HostName ^ Host { HostName ^ get(); void set(HostName ^ value); };
HostName Host();

void Host(HostName value);
public HostName Host { get; set; }
var hostName = httpRequestHeaderCollection.host;
httpRequestHeaderCollection.host = hostName;
Public Property Host As 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());
}

Applies to

See also