WebResponse.ContentLength 속성

정의

서브클래스에서 재정의될 때, 수신 중인 데이터의 콘텐츠 길이를 가져오거나 설정합니다.When overridden in a descendant class, gets or sets the content length of data being received.

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

속성 값

인터넷 리소스에서 반환된 바이트 수입니다.The number of bytes returned from the Internet resource.

예외

속성이 서브클래스에서 재정의되지 않았는데 속성을 가져오거나 설정하려 할 경우Any attempt is made to get or set the property, when the property is not overridden in a descendant class.

예제

다음 예제에서는 ContentLength 리소스의 길이를 가져오는 속성을 반환 합니다.The following example uses the ContentLength property to obtain the Length of the resource returned.

// 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 속성 인터넷 리소스에서 응답의 길이 (바이트)를 포함 합니다.The ContentLength property contains the length, in bytes, of the response from the Internet resource. 헤더 정보가 포함 된 요청 메서드는 ContentLength 길이 헤더 정보를 포함 되지 않습니다.For request methods that contain header information, the ContentLength does not include the length of the header information.

참고

합니다 WebResponse 클래스는 abstract 클래스입니다.The WebResponse class is an abstract class. 실제 동작 WebResponse 런타임 시 인스턴스 반환한 하위 클래스에 의해 결정 됩니다 WebRequest.GetResponse합니다.The actual behavior of WebResponse instances at run time is determined by the descendant class returned by WebRequest.GetResponse. 기본 값 및 예외에 대 한 자세한 내용은 참조 하십시오 하위 클래스에 대 한 설명서와 같은 HttpWebResponseFileWebResponse입니다.For more information about default values and exceptions, please see the documentation for the descendant classes, such as HttpWebResponse and FileWebResponse.

적용 대상

추가 정보