HttpListenerRequest.ContentLength64 Proprietà

Definizione

Ottiene la lunghezza dei dati del corpo inclusi nella richiesta.

C#
public long ContentLength64 { get; }

Valore della proprietà

Valore dell'intestazione Content-Length della richiesta. Se la lunghezza del contenuto non è nota, il valore è uguale a -1.

Esempio

Nell'esempio di codice seguente viene usata la proprietà durante l'elaborazione ContentLength64 dei dati del corpo.

C#
public static void ShowRequestData (HttpListenerRequest request)
{
    if (!request.HasEntityBody)
    {
        Console.WriteLine("No client data was sent with the request.");
        return;
    }
    System.IO.Stream body = request.InputStream;
    System.Text.Encoding encoding = request.ContentEncoding;
    System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
    if (request.ContentType != null)
    {
        Console.WriteLine("Client data content type {0}", request.ContentType);
    }
    Console.WriteLine("Client data content length {0}", request.ContentLength64);

    Console.WriteLine("Start of client data:");
    // Convert the data to a string and display it on the console.
    string s = reader.ReadToEnd();
    Console.WriteLine(s);
    Console.WriteLine("End of client data:");
    body.Close();
    reader.Close();
    // If you are finished with the request, it should be closed also.
}

Commenti

L'intestazione Content-Length esprime la lunghezza, in byte, dei dati del corpo che accompagnano la richiesta.

Per un elenco completo di intestazioni di richiesta, vedere l'enumerazione HttpRequestHeader .

Si applica a

Prodotto Versioni
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Vedi anche