HttpRequestHeaderCollection.Host 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
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());
}