using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;namespace HostConsole{ class Program { static void Main(string[] args) { if (HttpListener.IsSupported) { HttpListener listener = new HttpListener(); listener.Prefixes.Add("http://+:8080/"); listener.Start(); while (true) { Console.Write(DateTime.Now.ToString()); HttpListenerContext context = listener.GetContext(); string page = context.Request.Url.LocalPath.Replace("/",""); String query = context.Request.Url.Query.Replace("?", ""); StreamReader sr = new StreamReader(context.Request.InputStream); Console.WriteLine(sr.ReadToEnd()); Console.WriteLine("接收到请求:{0}?{1}", page, query); StreamWriter sw = new StreamWriter(context.Response.OutputStream); sw.Write("Hello World!"); sw.Flush(); context.Response.Close(); } } } }}