1.创建一个控制台工程,输入如下代码
static void Main(string[] args)
{
if(!HttpListener.IsSupported)
{
throw new System.InvalidOperationException("版本太低");
}
string[] prefixes = new string[] { "http://localhost:50000/" };
HttpListener listener = new HttpListener();
// 添加前缀
foreach(string s in prefixes)
{
listener.Prefixes.Add(s);
}
// 开始监听
listener.Start();
Console.WriteLine("监听中、、");
while (true)
{
HttpListenerContext context = listener.GetContext();
// 取得请求对象
HttpListenerRequest request = context.Request;
Console.WriteLine("{0} {1} HTTP/1.1", request.HttpMethod, request.RawUrl);
Console.WriteLine("A