HttpListenerRequest.InputStream 속성

정의

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

C#
public System.IO.Stream InputStream { get; }

속성 값

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

예제

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

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.
}

설명

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

참고

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

호출자 참고

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

적용 대상

제품 버전
.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

추가 정보