HttpListenerRequest.InputStream Vlastnost

Definice

Získá datový proud, který obsahuje data těla odeslaná klientem.

public:
 property System::IO::Stream ^ InputStream { System::IO::Stream ^ get(); };
public System.IO.Stream InputStream { get; }
member this.InputStream : System.IO.Stream
Public ReadOnly Property InputStream As Stream

Hodnota vlastnosti

Čitelný Stream objekt, který obsahuje bajty odeslané klientem v textu požadavku. Tato vlastnost se vrátí Null , pokud se spolu s požadavkem nepošlou žádná data.

Příklady

Následující příklad kódu ukazuje použití této vlastnosti ke čtení dat odeslaných s požadavkem.

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.
}
Public Shared Sub ShowRequestData(ByVal request As HttpListenerRequest)
    If Not request.HasEntityBody Then
        Console.WriteLine("No client data was sent with the request.")
        Return
    End If

    Dim body As System.IO.Stream = request.InputStream
    Dim encoding As System.Text.Encoding = request.ContentEncoding
    Dim reader As System.IO.StreamReader = New System.IO.StreamReader(body, encoding)

    If request.ContentType IsNot Nothing Then
        Console.WriteLine("Client data content type {0}", request.ContentType)
    End If

    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.
    Dim s As String = 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.
End Sub

Poznámky

Pokud klient přenáší data (například pomocí metody HTTP POST ), datový proud vrácený touto metodou obsahuje tato data.

Poznámka

Při zavření požadavku nedojde k zavření datového proudu vráceného touto vlastností. Pokud už datový proud nepotřebujete, měli byste ho Close zavřít voláním metody .

Poznámky pro volající

Tento člen poskytuje trasovací informace, když je ve vaší aplikaci povoleno trasování sítě. Další informace naleznete v tématu Trasování sítě v rozhraní .NET Framework.

Platí pro

Viz také