WebRequest.ContentType Vlastnost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Při přepsání v následné 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 potomkovací 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í obsahu MIME.
Poznámka
Třída WebRequest je abstract
třída. Skutečné chování WebRequest instancí za běhu je určeno následnou 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é
Váš názor
https://aka.ms/ContentUserFeedback.
Připravujeme: V průběhu roku 2024 budeme postupně vyřazovat problémy z GitHub coby mechanismus zpětné vazby pro obsah a nahrazovat ho novým systémem zpětné vazby. Další informace naleznete v tématu:Odeslat a zobrazit názory pro