WebResponse.ContentLength 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在子系類別中覆寫時,取得或設定正在接收資料的內容長度。
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
屬性值
傳回自網際網路資源的位元組數。
例外狀況
當屬性在子代類別中未覆寫時,會嘗試取得或設定該屬性。
範例
下列範例會 ContentLength 使用 屬性來取得傳回之資源的 Length。
// 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()
備註
屬性 ContentLength 包含來自因特網資源的回應長度,以位元組為單位。 對於包含標頭資訊的要求方法, ContentLength 不包含標頭信息的長度。
注意
類別 WebResponse 是類別 abstract
。 運行時間實例的實際行為是由 所WebRequest.GetResponse傳回的WebResponse子系類別所決定。 如需預設值和例外狀況的詳細資訊,請參閱 子系類別的檔,例如 HttpWebResponse 和 FileWebResponse。