WebResponse.ContentLength Vlastnost

Definice

Při přepsání v potomkovací třídě získá nebo nastaví délku obsahu přijatých dat.

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

Hodnota vlastnosti

Int64

Počet bajtů vrácených z internetového prostředku.

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 používá ContentLength vlastnost k získání délky vráceného prostředku.

// Create a 'WebRequest' with the specified url.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" );

// Send the 'WebRequest' and wait for response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Display the content length and content type received as headers in the response object.
Console::WriteLine( "\nContent length : {0}, Content Type : {1}", myWebResponse->ContentLength, myWebResponse->ContentType );

// Release resources of response object.
myWebResponse->Close();

         // Create a 'WebRequest' with the specified url.
WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com"); 

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Display the content length and content type received as headers in the response object.
Console.WriteLine("\nContent length :{0}, Content Type : {1}", 
                             myWebResponse.ContentLength, 
                             myWebResponse.ContentType);  

// Release resources of response object.
myWebResponse.Close();

' Create a 'WebRequest' with the specified url. 	
Dim myWebRequest As WebRequest = WebRequest.Create("www.contoso.com")

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

' The ContentLength and ContentType received as headers in the response object are also exposed as properties.
   ' These provide information about the length and type of the entity body in the response.
Console.WriteLine(ControlChars.Cr + "Content length :{0}, Content Type : {1}", myWebResponse.ContentLength, myWebResponse.ContentType)
myWebResponse.Close()

Poznámky

Vlastnost ContentLength obsahuje délku odpovědi z internetového prostředku v bajtech. Pro metody požadavku, které obsahují informace o hlavičce, ContentLength nezahrnuje délku informací záhlaví.

Poznámka

Třída WebResponse je abstract třída. Skutečné chování WebResponse instancí za běhu je určeno potomkem třídy vrácenou WebRequest.GetResponse. Další informace o výchozích hodnotách a výjimkách najdete v dokumentaci pro třídy potomků, například HttpWebResponse a FileWebResponse.

Platí pro

Viz také