Export (0) Print
Expand All

HttpWebRequest.Accept Property

Gets or sets the value of the Accept HTTP header.

[Visual Basic]
Public Property Accept As String
[C#]
public string Accept {get; set;}
[C++]
public: __property String* get_Accept();
public: __property void set_Accept(String*);
[JScript]
public function get Accept() : String;
public function set Accept(String);

Property Value

The value of the Accept HTTP header. The default value is a null reference (Nothing in Visual Basic).

Remarks

To clear the Accept HTTP header, set the Accept property to a null reference (Nothing in Visual Basic).

Example

[Visual Basic, C#, C++] The following example sets the Accept property.

[Visual Basic] 
' 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)

[C#] 
// 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();

[C++] 
// Create a 'HttpWebRequest' object.
HttpWebRequest* myHttpWebRequest = 
   dynamic_cast<HttpWebRequest*>(WebRequest::Create(myUri));
// Set the 'Accept' property to accept an image of any type.
myHttpWebRequest->Accept=S"image/*";
// The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
HttpWebResponse* myHttpWebResponse =
   dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

HttpWebRequest Class | HttpWebRequest Members | System.Net Namespace

Show:
© 2015 Microsoft