다음을 통해 공유


HttpWebRequest.ContentType Property

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

Gets or sets the value of the Content-type HTTP header.

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

Syntax

'Declaration
Public Overrides Property ContentType As String
public override string ContentType { get; set; }

Property Value

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

Remarks

The ContentType property contains the media type of the request. Values assigned to the ContentType property replace any existing contents when the request sends the Content-type HTTP header.

To clear the Content-type HTTP header, set the ContentType property to nulla null reference (Nothing in Visual Basic).

NoteNote:

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

Examples

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

' Create a 'HttpWebRequest' object.
Dim myHttpWebRequest As HttpWebRequest = WebRequest.Create(myUri)

' Set the 'Method' property to "POST".
myHttpWebRequest.Method="PUT"

' Set the 'ContentType' property.
myHttpWebRequest.ContentType="application/x-www-form-urlencoded"

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

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

        // Set the 'Method' property to "POST".
        myHttpWebRequest.Method="PUT";

        // Set the 'ContentType' property.
        myHttpWebRequest.ContentType="application/x-www-form-urlencoded";

        // Get the 'ContentType' property and print the current value
        outputBlock.Text += "HttpWebRequest.ContentType: ";
        outputBlock.Text += myHttpWebRequest.ContentType;
        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.