WebResponse.ContentLength Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Quando sottoposto a override in una classe discendente, ottiene o imposta la lunghezza del contenuto dei dati ricevuti.
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
Valore della proprietà
Numero di byte restituiti dalla risorsa Internet.
Eccezioni
Qualsiasi tentativo viene effettuato per ottenere o impostare la proprietà, quando la proprietà non viene sottoposta a override in una classe discendente.
Esempio
Nell'esempio seguente viene utilizzata la ContentLength proprietà per ottenere la lunghezza della risorsa restituita.
// 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()
Commenti
La ContentLength proprietà contiene la lunghezza, in byte, della risposta dalla risorsa Internet. Per i metodi di richiesta che contengono informazioni sull'intestazione, ContentLength non include la lunghezza delle informazioni sull'intestazione.
Annotazioni
La WebResponse classe è una abstract classe . Il comportamento effettivo delle istanze in fase di WebResponse esecuzione è determinato dalla classe discendente restituita da WebRequest.GetResponse. Per altre informazioni sui valori predefiniti e sulle eccezioni, vedere la documentazione per le classi discendenti, ad esempio HttpWebResponse e FileWebResponse.