HttpListenerRequest.InputStream 속성

정의

클라이언트에서 보낸 본문 데이터가 들어 있는 스트림을 가져옵니다.

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

속성 값

클라이언트에서 요청 본문에 보낸 바이트가 들어 있는 읽기 가능한 Stream 개체입니다. 요청과 함께 데이터를 보내지 않은 경우 이 속성은 Null을 반환합니다.

예제

다음 코드 예제에서는 이 속성을 사용하여 요청과 함께 전송된 데이터를 읽는 방법을 보여 줍니다.

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

설명

클라이언트가 데이터를 전송하는 경우(예: HTTP POST 메서드 사용) 이 메서드에서 반환된 스트림에는 해당 데이터가 포함됩니다.

참고

요청을 닫아도 이 속성에서 반환된 스트림이 닫히지 않습니다. 스트림이 더 이상 필요하지 않은 경우 메서드를 호출하여 스트림을 Close 닫아야 합니다.

호출자 참고

애플리케이션에 네트워크 추적을 사용하도록 설정하면 이 멤버에서 추적 정보를 출력합니다. 자세한 내용은 .NET Framework 네트워크 추적을 참조하세요.

적용 대상

추가 정보