HttpListenerRequest 클래스

정의

HttpListener 개체에 대한 들어오는 HTTP 요청을 설명합니다. 이 클래스는 상속될 수 없습니다.

public ref class HttpListenerRequest sealed
public sealed class HttpListenerRequest
type HttpListenerRequest = class
Public NotInheritable Class HttpListenerRequest
상속
HttpListenerRequest

예제

다음 코드 예제에서는 수신 하 고 응답 하는 HttpListenerRequest방법을 보여 줍니다.

// This example requires the System and System.Net namespaces.
public static void SimpleListenerExample(string[] prefixes)
{
    if (!HttpListener.IsSupported)
    {
        Console.WriteLine ("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
        return;
    }
    // URI prefixes are required,
    // for example "http://contoso.com:8080/index/".
    if (prefixes == null || prefixes.Length == 0)
      throw new ArgumentException("prefixes");

    // Create a listener.
    HttpListener listener = new HttpListener();
    // Add the prefixes.
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    Console.WriteLine("Listening...");
    // Note: The GetContext method blocks while waiting for a request.
    HttpListenerContext context = listener.GetContext();
    HttpListenerRequest request = context.Request;
    // Obtain a response object.
    HttpListenerResponse response = context.Response;
    // Construct a response.
    string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
    // Get a response stream and write the response to it.
    response.ContentLength64 = buffer.Length;
    System.IO.Stream output = response.OutputStream;
    output.Write(buffer,0,buffer.Length);
    // You must close the output stream.
    output.Close();
    listener.Stop();
}
Public Shared Sub SimpleListenerExample(prefixes As String())
    If Not HttpListener.IsSupported Then
        Console.WriteLine("Windows XP SP2 or Server 2003 is required to use the HttpListener class.")
        Return
    End If
    ' URI prefixes are required,
    ' for example "http://contoso.com:8080/index/".
    If prefixes Is Nothing Or prefixes.Length = 0 Then
        Throw New ArgumentException("prefixes")
    End If

    ' Create a listener
    Dim listener = New HttpListener()

    For Each s As String In prefixes
        listener.Prefixes.Add(s)
    Next
    listener.Start()
    Console.WriteLine("Listening...")
    ' Note: The GetContext method blocks while waiting for a request.
    Dim context As HttpListenerContext = listener.GetContext()
    Console.WriteLine("Listening...")
    ' Obtain a response object
    Dim request As HttpListenerRequest = context.Request
    ' Construct a response.
    Dim response As HttpListenerResponse = context.Response
    Dim responseString As String = "<HTML><BODY> Hello world!</BODY></HTML>"
    Dim buffer As Byte() = System.Text.Encoding.UTF8.GetBytes(responseString)
    ' Get a response stream and write the response to it.
    response.ContentLength64 = buffer.Length
    Dim output As System.IO.Stream = response.OutputStream
    output.Write(buffer, 0, buffer.Length)
    'You must close the output stream.
    output.Close()
    listener.Stop()
End Sub

설명

클라이언트가 개체에 의해 HttpListener 처리되는 URI(Uniform Resource Identifier)에 요청을 하면 보낸 사람, HttpListener 요청 및 클라이언트로 전송되는 응답에 대한 정보가 포함된 개체를 제공합니다 HttpListenerContext . 이 속성은 HttpListenerContext.Request 요청을 설명하는 개체를 반환 HttpListenerRequest 합니다.

개체에는 HttpListenerRequest 요청 문자열, UserAgent 문자열 및 요청 본문 데이터와 같은 요청에 HttpMethod 대한 정보가 포함됩니다(속성 참조InputStream).

요청에 회신하려면 속성을 사용하여 Response 연결된 응답을 가져와야 합니다.

속성

AcceptTypes

클라이언트에서 받아들일 수 있는 MIME 형식을 가져옵니다.

ClientCertificateError

클라이언트에서 제공한 X509Certificate와 관련된 문제를 식별하는 오류 코드를 가져옵니다.

ContentEncoding

요청과 함께 전송된 데이터에 사용할 수 있는 콘텐츠 인코딩을 가져옵니다.

ContentLength64

요청에 포함된 본문 데이터의 길이를 가져옵니다.

ContentType

요청에 포함된 본문 데이터의 MIME 형식을 가져옵니다.

Cookies

요청과 함께 전송된 쿠키를 가져옵니다.

HasEntityBody

요청에 관련된 본문 데이터가 있는지 여부를 나타내는 Boolean 값을 가져옵니다.

Headers

요청에서 보낸 헤더 이름/값 쌍의 컬렉션을 가져옵니다.

HttpMethod

클라이언트에서 지정한 HTTP 메서드를 가져옵니다.

InputStream

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

IsAuthenticated

이 요청을 보내는 클라이언트가 인증되었는지 여부를 나타내는 Boolean 값입니다.

IsLocal

요청을 로컬 컴퓨터에서 보냈는지 여부를 나타내는 Boolean 값을 가져옵니다.

IsSecureConnection

요청을 보내는 데 사용된 TCP 연결이 SSL(Secure Sockets Layer) 프로토콜을 사용하는지 여부를 나타내는 Boolean 값을 가져옵니다.

IsWebSocketRequest

TCP 연결이 WebSocket 요청인지 여부를 나타내는 Boolean 값을 가져옵니다.

KeepAlive

클라이언트에서 영구 연결을 요청하는지 여부를 나타내는 Boolean 값을 가져옵니다.

LocalEndPoint

요청이 전달되는 서버 IP 주소 및 포트 번호를 가져옵니다.

ProtocolVersion

요청하는 클라이언트에서 사용하는 HTTP 버전을 가져옵니다.

QueryString

요청에 포함된 쿼리 문자열을 가져옵니다.

RawUrl

클라이언트에서 요청한 URL 정보(호스트 및 포트 제외)를 가져옵니다.

RemoteEndPoint

요청이 시작된 클라이언트 IP 주소 및 포트 번호를 가져옵니다.

RequestTraceIdentifier

들어오는 HTTP 요청의 요청 식별자를 가져옵니다.

ServiceName

클라이언트가 요청에 대해 보낸 SPN(서비스 공급자 이름)을 가져옵니다.

TransportContext

클라이언트 요청에 대한 TransportContext를 가져옵니다.

Url

클라이언트에서 요청한 Uri 개체를 가져옵니다.

UrlReferrer

클라이언트를 서버에 연결시킨 리소스의 URI(Uniform Resource Identifier)를 가져옵니다.

UserAgent

클라이언트에서 표시한 사용자 에이전트를 가져옵니다.

UserHostAddress

요청이 전달되는 서버 IP 주소 및 포트 번호를 가져옵니다.

UserHostName

DNS 이름과 클라이언트에서 지정한 포트 번호(제공된 경우)를 가져옵니다.

UserLanguages

응답에 대해 기본 설정된 자연 언어를 가져옵니다.

메서드

BeginGetClientCertificate(AsyncCallback, Object)

클라이언트의 X.509 v.3 인증서에 대한 비동기 요청을 시작합니다.

EndGetClientCertificate(IAsyncResult)

클라이언트의 X.509 v.3 인증서에 대한 비동기 요청을 끝냅니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetClientCertificate()

클라이언트의 X.509 v.3 인증서를 가져옵니다.

GetClientCertificateAsync()

클라이언트의 X.509 v.3 인증서를 비동기 작업으로 검색합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보