Public NotInheritable Class HttpListenerRequest
Dim instance As HttpListenerRequest
public sealed class HttpListenerRequest
public ref class HttpListenerRequest sealed
public final class HttpListenerRequest
클라이언트가 HttpListener 개체에서 처리되는 URI(Uniform Resource Identifier)에 요청을 하면 HttpListener에서는 송신자, 요청 및 클라이언트에 보내는 응답에 대한 정보가 들어 있는 HttpListenerContext 개체를 제공합니다. HttpListenerContext.Request 속성은 요청을 설명하는 HttpListenerRequest 개체를 반환합니다.
HttpListenerRequest 개체에는 요청의 HttpMethod 문자열, UserAgent 문자열 및 요청 본문 데이터(InputStream 속성 참조)와 같은 요청 관련 정보가 들어 있습니다.
요청에 회신하려면 Response 속성을 사용하여 관련 응답을 가져와야 합니다.
다음 코드 예제에서는 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(); }
Windows 98, Windows Server 2003, Windows XP Media Center Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.