1using System.Collections;
2using System.Collections.Generic;
5using System.Threading.Tasks;
11 private readonly HttpListener _listener =
new HttpListener();
12 public Dictionary<string, byte[]>
loadedFiles =
new Dictionary<string, byte[]>();
15 bool flag = !HttpListener.IsSupported;
18 throw new NotSupportedException(
"Needs Windows XP SP2, Server 2003 or later.");
21 this._listener.Prefixes.Add(
"http://*:8069/");
23 this._listener.Start();
27 this._listener.Stop();
28 this._listener.Close();
33 ThreadPool.QueueUserWorkItem(delegate (
object o)
35 Console.WriteLine(
"web server started...");
38 while (this._listener.IsListening)
40 ThreadPool.QueueUserWorkItem(delegate (object c)
42 HttpListenerContext httpListenerContext = c as HttpListenerContext;
45 Console.WriteLine(
"AbsolutePath request: " + httpListenerContext.Request.Url.AbsolutePath);
46 var file = httpListenerContext.Request.Url.AbsolutePath.Remove(0, 1);
48 if (loadedFiles.ContainsKey(file))
50 byte[] bytes = loadedFiles[httpListenerContext.Request.Url.AbsolutePath.Remove(0, 1)];
51 httpListenerContext.Response.ContentLength64 = (long)bytes.Length;
52 httpListenerContext.Response.OutputStream.Write(bytes, 0, bytes.Length);
60 httpListenerContext.Response.OutputStream.Close();
62 },
this._listener.GetContext());
Dictionary< string, byte[]> loadedFiles