WebRequest.ContentType Vlastnost

Definice

Při přepsání v odvozené třídě získá nebo nastaví typ obsahu odesílaných dat požadavku.

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

Hodnota vlastnosti

Typ obsahu dat požadavku.

Výjimky

Jakýkoli pokus o získání nebo nastavení vlastnosti, pokud vlastnost není přepsána v odvozené třídě.

Příklady

Následující příklad nastaví ContentType vlastnost na odpovídající typ média.

// 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()

Poznámky

Vlastnost ContentType obsahuje typ média požadavku. Obvykle se jedná o kódování MIME obsahu.

Poznámka

Třída WebRequest je abstract třída. Skutečné chování WebRequest instancí za běhu je určeno odvozenou třídou vrácenou metodou WebRequest.Create . Další informace o výchozích hodnotách a výjimkách najdete v dokumentaci pro odvozené třídy, například HttpWebRequest a FileWebRequest.

Platí pro

Viz také