HttpRequestHeaderCollection.Host 屬性

定義

取得或設定 HostName ,表示 HTTP 要求上 主機 HTTP 標頭的值。

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

屬性值

HostName,表示 HTTP 要求上主機HTTP 標頭的值。 Null 值表示標頭不存在。

備註

下列範例程式碼示範如何使用HttpRequestHeaderCollection物件的 Host 屬性,在HttpRequestMessage物件上設定Host標頭的方法。

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

適用於

另請參閱