WebRequest.ContentLength Właściwość

Definicja

Po przesłonięciu w klasie potomnej pobiera lub ustawia długość zawartości wysyłanych danych żądania.

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

Wartość właściwości

Liczba bajtów wysyłanych danych żądania.

Wyjątki

Każda próba pobrania lub ustawienia właściwości, gdy właściwość nie jest zastępowana w klasie potomnej.

Przykłady

Poniższy przykład ustawia ContentLength właściwość na ilość bajtów w buforze bajtów wychodzących.

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

Uwagi

Właściwość ContentLength zawiera liczbę bajtów danych wysyłanych do zasobu internetowego WebRequest przez wystąpienie.

Uwaga

Klasa WebRequest jest klasą abstract . Rzeczywiste zachowanie WebRequest wystąpień w czasie wykonywania jest określane przez klasę potomną zwróconą przez metodę WebRequest.Create . Aby uzyskać więcej informacji na temat wartości domyślnych i wyjątków, zobacz dokumentację dla klas potomnych, takich jak HttpWebRequest i FileWebRequest.

Dotyczy

Zobacz też