HttpWebRequest.Accept 属性

定义

获取或设置 Accept HTTP 标头的值。

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

属性值

Accept HTTP 标头的值。 默认值为 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.
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)

注解

谨慎

WebRequestHttpWebRequestServicePointWebClient 已过时,不应将其用于新开发。 请改用 HttpClient

若要清除 Accept HTTP 标头,请将 Accept 属性设置为 null

注意

此属性的值存储在 WebHeaderCollection中。 如果设置了 WebHeaderCollection,则属性值将丢失。

适用于