HttpWebRequest.Accept Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the value of the Accept HTTP header.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

Syntax

'Declaration
Public Property Accept As String
public string Accept { get; set; }

Property Value

Type: System.String
The value of the Accept HTTP header. The default value is nulla null reference (Nothing in Visual Basic).

Remarks

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

NoteNote:

The value for this property is stored in WebHeaderCollection. If WebHeaderCollection is set, the property value is lost.

Examples

' Change this Uri to a public server
Dim myUri As System.Uri = New Uri("http://www.contoso.com")

' 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/*"

' Get the 'Accept' property and print the current value
outputBlock.Text &= "HttpWebRequest.Accept: "
outputBlock.Text &= myHttpWebRequest.Accept
outputBlock.Text &= vbCrLf
        // Change this Uri to a public server
        System.Uri myUri = new Uri("http://www.contoso.com");

        // Create a 'HttpWebRequest' object.
        HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);

        // Set the 'Accept' property to accept an image of any type.
        myHttpWebRequest.Accept="image/*";

        // Get the 'Accept' property and print the current value
        outputBlock.Text += "HttpWebRequest.Accept: ";
        outputBlock.Text += myHttpWebRequest.Accept;
        outputBlock.Text += "\n";

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.