WebRequest.ContentLength WebRequest.ContentLength WebRequest.ContentLength WebRequest.ContentLength Property

定义

当在子类中被重写时,获取或设置所发送的请求数据的内容长度。When overridden in a descendant class, gets or sets the content length of the request data being sent.

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 of request data being sent.

异常

当未在子类中重写该属性时,试图获取或设置该属性。Any attempt is made to get or set the property, when the property is not overridden in a descendant class.

示例

下面的示例将ContentLength属性设置为输出字节缓冲区中的字节数。The following example sets the ContentLength property to the amount of bytes in the outgoing byte buffer.

// Set the 'ContentType' property of the WebRequest.
myWebRequest->ContentType = "application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest->ContentLength = byteArray->Length;
Stream^ newStream = myWebRequest->GetRequestStream();
newStream->Write( byteArray, 0, byteArray->Length );

// Close the Stream object.
newStream->Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType="application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength=byteArray.Length;
Stream newStream=myWebRequest.GetRequestStream();
newStream.Write(byteArray,0,byteArray.Length);

// Close the Stream object.
newStream.Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse=myWebRequest.GetResponse();



' Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType = "application/x-www-form-urlencoded"

' Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength = byteArray.Length
Dim newStream As Stream = myWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)

' Close the Stream object.
newStream.Close()

' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

注解

属性包含WebRequest实例发送到 Internet 资源的数据的字节数。 ContentLengthThe ContentLength property contains the number of bytes of data sent to the Internet resource by the WebRequest instance.

备注

类是一个abstract类。 WebRequestThe WebRequest class is an abstract class. WebRequest实例在运行时的实际行为由WebRequest.Create方法返回的子代类确定。The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the WebRequest.Create method. 有关默认值和异常的详细信息,请参阅子代类的文档,例如HttpWebRequest和。 FileWebRequestFor more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.

适用于

另请参阅