Aracılığıyla paylaş


WebRequest.ContentLength Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When overridden in a descendant class, gets or sets the content length of the request data being sent.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

Syntax

'Declaration
Public Overridable Property ContentLength As Long
public virtual long ContentLength { get; set; }

Property Value

Type: System.Int64
The number of bytes of request data being sent.

Exceptions

Exception Condition
NotImplementedException

Any attempt is made to get or set the property, when the property is not overridden in a descendant class.

Remarks

The ContentLength property contains the number of bytes of data sent to the Internet resource by the WebRequest instance.

The ContentLength property can be used to set the Content-Length header on an instance of HttpWebRequest class. This property is supported on both the browser and client HTTP stacks. On the browser HTTP stack, the ContentLength property is not required to be set because the Silverlight runtime will automatically populate the Content-Length header with the correct value based on the buffered request body. If a Silverlight application on either the browser or client HTTP stack sets this property to a value that does not match the size of the provided request body, a ProtocolViolationException is thrown when the request is sent. On the client HTTP stack if AllowWriteStreamBuffering is false, the ContentLength property must be used to set the correct value of the Content-Length header before calling the BeginGetRequestStream method.

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.