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

속성 값

Int64

인터넷 리소스에서 반환된 바이트 수입니다.

예외

속성이 서브클래스에서 재정의되지 않았는데 속성을 가져오거나 설정하려 할 경우

예제

다음 예제에서는 속성을 사용하여 ContentLength 반환된 리소스의 길이를 가져옵니다.

// 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. 런타임에 인스턴스의 WebResponse 실제 동작은 반환된 하위 클래스 WebRequest.GetResponse에 의해 결정됩니다. 기본값 및 예외에 대한 자세한 내용은 다음과 같은 HttpWebResponse FileWebResponse하위 클래스에 대한 설명서를 참조하세요.

적용 대상

추가 정보