共用方式為


HttpWebRequest.Accept 屬性

定義

取得或設定 HTTP 標頭的 Accept 值。

public:
 property System::String ^ Accept { System::String ^ get(); void set(System::String ^ value); };
public string Accept { get; set; }
public string? Accept { get; set; }
member this.Accept : string with get, set
Public Property Accept As String

屬性值

HTTP 標頭的 Accept 值。 預設值為 null

範例

以下程式碼範例設定了屬性 Accept

// Create a 'HttpWebRequest' object.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);
// Set the 'Accept' property to accept an image of any type.
myHttpWebRequest.Accept="image/*";
// The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
' Create a 'HttpWebRequest' object.
Dim myHttpWebRequest As HttpWebRequest = WebRequest.Create(myUri)
' Set the 'Accept' property to accept an image of any type.
myHttpWebRequest.Accept = "image/*"
' The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

備註

謹慎

WebRequest、、HttpWebRequestServicePointWebClient、和 都已過時,你不應該用它們來做新開發。 請改用 HttpClient

要清除 HTTP 標頭, Accept 請將屬性設 Acceptnull

注意

此屬性的值儲存在 WebHeaderCollection。 如果已設定 WebHeaderCollection,屬性值就會遺失。

適用於