WebRequest.ContentType Właściwość

Definicja

Gdy zastąpisz klasę potomną, pobiera lub ustawia typ zawartości wysyłanych danych żądania.

public:
 abstract property System::String ^ ContentType { System::String ^ get(); void set(System::String ^ value); };
public:
 virtual property System::String ^ ContentType { System::String ^ get(); void set(System::String ^ value); };
public abstract string ContentType { get; set; }
public virtual string? ContentType { get; set; }
public virtual string ContentType { get; set; }
member this.ContentType : string with get, set
Public MustOverride Property ContentType As String
Public Overridable Property ContentType As String

Wartość właściwości

Typ zawartości danych żądania.

Wyjątki

Każda próba pobrania lub ustawienia właściwości jest podejmowana, gdy właściwość nie jest zastępowana w klasie potomnej.

Przykłady

Poniższy przykład ustawia ContentType właściwość na odpowiedni typ nośnika.

// Set the 'ContentType' property of the WebRequest.
myWebRequest->ContentType = "application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest->ContentLength = byteArray->Length;
Stream^ newStream = myWebRequest->GetRequestStream();
newStream->Write( byteArray, 0, byteArray->Length );

// Close the Stream object.
newStream->Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

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

// Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength=byteArray.Length;
Stream newStream=myWebRequest.GetRequestStream();
newStream.Write(byteArray,0,byteArray.Length);

// Close the Stream object.
newStream.Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse=myWebRequest.GetResponse();


' Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType = "application/x-www-form-urlencoded"

' Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength = byteArray.Length
Dim newStream As Stream = myWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)

' Close the Stream object.
newStream.Close()

' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

Uwagi

Właściwość ContentType zawiera typ nośnika żądania. Jest to zazwyczaj kodowanie MIME zawartości.

Uwaga

Klasa WebRequest jest klasą abstract . Rzeczywiste zachowanie WebRequest wystąpień w czasie wykonywania jest określane przez klasę potomną zwróconą przez metodę WebRequest.Create . Aby uzyskać więcej informacji na temat wartości domyślnych i wyjątków, zobacz dokumentację dla klas potomnych, takich jak HttpWebRequest i FileWebRequest.

Dotyczy

Zobacz też