HttpListener 클래스

정의

프로그래밍 방식으로 제어되는 간단한 HTTP 프로토콜 수신기를 제공합니다. 이 클래스는 상속할 수 없습니다.

public ref class HttpListener sealed : IDisposable
public sealed class HttpListener : IDisposable
type HttpListener = class
    interface IDisposable
Public NotInheritable Class HttpListener
Implements IDisposable
상속
HttpListener
구현

예제

// 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

설명

이 API에 대한 자세한 내용은 HttpListener에 대한 추가 API 비고를 참조하세요.

생성자

Name Description
HttpListener()

HttpListener 클래스의 새 인스턴스를 초기화합니다.

속성

Name Description
AuthenticationSchemes

클라이언트를 인증하는 데 사용되는 체계를 가져오거나 설정합니다.

AuthenticationSchemeSelectorDelegate

클라이언트를 인증하는 데 사용되는 프로토콜을 결정하기 위해 호출된 대리자를 가져오거나 설정합니다.

DefaultServiceNames

등록된 접두사로 결정되는 SPN(서비스 공급자 이름)의 기본 목록을 가져옵니다.

ExtendedProtectionPolicy

세션에 ExtendedProtectionPolicy 대한 확장된 보호에 사용할 값을 가져오거나 설정합니다.

ExtendedProtectionSelectorDelegate

각 요청에 사용할 대리자를 결정하기 위해 호출된 ExtendedProtectionPolicy 대리자를 가져오거나 설정합니다.

IgnoreWriteExceptions

애플리케이션이 클라이언트에 Boolean 응답을 보낼 때 HttpListener 발생하는 예외를 받을지 여부를 지정하는 값을 가져오거나 설정합니다.

IsListening

시작되었는지 여부를 HttpListener 나타내는 값을 가져옵니다.

IsSupported

현재 운영 체제에서 사용할 수 있는지 여부를 HttpListener 나타내는 값을 가져옵니다.

Prefixes

HttpListener 개체에서 처리하는 URI(Uniform Resource Identifier) 접두사를 가져옵니다.

Realm

HttpListener 개체와 연결된 영역 또는 리소스 파티션을 가져오거나 설정합니다.

TimeoutManager

HttpListener 인스턴스의 시간 제한 관리자입니다.

UnsafeConnectionNtlmAuthentication

NTLM을 사용하는 경우 인증에 동일한 TCP(Transmission Control Protocol) 연결을 사용하는 추가 요청이 필요한지 여부를 제어하는 값을 가져오거나 설정합니다 Boolean .

메서드

Name Description
Abort()

개체를 HttpListener 즉시 종료하여 현재 대기 중인 모든 요청을 삭제합니다.

BeginGetContext(AsyncCallback, Object)

들어오는 요청을 비동기적으로 검색하기 시작합니다.

Close()

를 종료 HttpListener합니다.

EndGetContext(IAsyncResult)

들어오는 클라이언트 요청을 검색하는 비동기 작업을 완료합니다.

Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.

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

들어오는 요청을 대기하고 수신될 때 반환합니다.

GetContextAsync()

들어오는 요청을 비동기 작업으로 기다립니다.

GetHashCode()

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

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

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

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

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

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

이 인스턴스가 들어오는 요청을 수신하도록 허용합니다.

Stop()

이 인스턴스가 들어오는 새 요청 수신을 중지하고 진행 중인 모든 요청의 처리를 종료합니다.

ToString()

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

(다음에서 상속됨 Object)

명시적 인터페이스 구현

Name Description
IDisposable.Dispose()

HttpListener 개체가 보유한 리소스를 해제합니다.

적용 대상

추가 정보