WebResponse.ContentLength 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
当在子类中重写时,获取或设置接收的数据的内容长度。
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
属性值
从 Internet 资源返回的字节数。
例外
当未在子类中重写该属性时,试图获取或设置该属性。
示例
以下示例使用 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 包含来自 Internet 资源的响应的长度(以字节为单位)。 对于包含标头信息的请求方法, ContentLength 不包括标头信息的长度。
注意
类 WebResponse 是类 abstract
。 实例在运行时的实际行为 WebResponse 由 返回 WebRequest.GetResponse的后代类确定。 有关默认值和异常的详细信息,请参阅后代类的文档,例如 HttpWebResponse 和 FileWebResponse。