WebResponse.ContentType 속성

정의

파생 클래스에서 재정의될 때, 수신 중인 데이터의 콘텐츠 형식을 가져오거나 설정합니다.When overridden in a derived class, gets or sets the content type of the data being received.

public:
 virtual property System::String ^ ContentType { System::String ^ get(); void set(System::String ^ value); };
public virtual string ContentType { get; set; }
member this.ContentType : string with get, set
Public Overridable Property ContentType As String

속성 값

응답의 콘텐츠 형식이 들어 있는 문자열입니다.A string that contains the content type of the response.

예외

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

예제

다음 예제에서는 ContentType 속성 응답의 콘텐츠 형식을 가져옵니다.The following example uses the ContentType property to obtain the content type of the response.

// 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()

설명

ContentType 속성 알 수 있는 경우 인터넷 리소스 로부터의 응답이의 MIME 콘텐츠 형식을 포함 합니다.The ContentType property contains the MIME content type of the response from the Internet resource, if known.

참고

합니다 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.

적용 대상

추가 정보