WebResponse.ContentType 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当在派生类中重写时,获取或设置接收的数据的内容类型。
public:
 abstract property System::String ^ ContentType { System::String ^ get(); };public:
 virtual property System::String ^ ContentType { System::String ^ get(); void set(System::String ^ value); };public abstract string ContentType { get; }public virtual string ContentType { get; set; }member this.ContentType : stringmember this.ContentType : string with get, setPublic MustOverride ReadOnly Property ContentType As StringPublic Overridable Property ContentType As String属性值
包含响应的内容类型的字符串。
例外
当未在子类中重写该属性时,试图获取或设置该属性。
示例
以下示例使用 ContentType 属性获取响应的内容类型。
         // 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 包含来自 Internet 资源的响应的 MIME 内容类型(如果已知)。
注意
类 WebResponse 是类 abstract 。 实例在运行时的实际行为 WebResponse 由 返回 WebRequest.GetResponse的后代类确定。 有关默认值和异常的详细信息,请参阅后代类的文档,例如 HttpWebResponse 和 FileWebResponse。