WebRequest.ContentLength Vlastnost

Definice

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

public:
 virtual property long ContentLength { long get(); void set(long value); };
public virtual long ContentLength { get; set; }
member this.ContentLength : int64 with get, set
Public Overridable Property ContentLength As Long

Hodnota vlastnosti

Počet bajtů odesílaných dat požadavků.

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í ContentLength vlastnost na množství bajtů v vyrovnávací paměti odchozích bajtů.

// 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 ContentLength obsahuje počet bajtů dat odeslaných do internetového prostředku WebRequest instancí.

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é