HttpWebRequest.Accept 属性

定义

获取或设置 Accept HTTP 标头的值。Gets or sets the value of the Accept HTTP header.

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

属性值

Accept HTTP 标头的值。The value of the Accept HTTP header. 默认值为 nullThe default value is null.

示例

下面的代码示例设置 Accept 属性。The following code example sets the Accept property.

// 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)

注解

若要清除 Accept HTTP 标头,请将 Accept 属性设置为 "null"。To clear the Accept HTTP header, set the Accept property to null.

备注

此属性的值存储在 WebHeaderCollection 中。The value for this property is stored in WebHeaderCollection. 如果设置了 WebHeaderCollection,则该属性值将丢失。If WebHeaderCollection is set, the property value is lost.

适用于