WebResponse.ContentLength プロパティ

定義

派生クラスでオーバーライドされると、受信しているデータのコンテンツ長を取得または設定します。

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 にはヘッダー情報の長さは含まれません。

Note

クラスは WebResponse クラスです abstract 。 実行時のインスタンスの実際の WebResponse 動作は、 によって返される子孫クラスによって WebRequest.GetResponse決定されます。 既定値と例外の詳細については、 や FileWebResponseなどのHttpWebResponse子孫クラスのドキュメントを参照してください。

適用対象

こちらもご覧ください