HttpWebRequest.Accept Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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; }
public string? Accept { get; set; }
member this.Accept : string with get, set
Public Property Accept As String
Property Value
The value of the Accept
HTTP header. The default value is null
.
Examples
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)
Remarks
Caution
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
To clear the Accept
HTTP header, set the Accept property to null
.
Note
The value for this property is stored in WebHeaderCollection. If WebHeaderCollection is set, the property value is lost.