public void start() { if (listener != null) { listener.Stop(); listener.Prefixes.Clear(); } else { listener = new HttpListener(); } //string prefix = "http://localhost:8088/"; string prefix = "http://localhost:" + this.port.ToString() + "/"; //listener = new HttpListener(); listener.Prefixes.Add(prefix); // プレフィックスの登録 listener.Start(); isbusy = true; //listener.BeginGetContext(OnGetContext, listener); while (isbusy) { HttpListenerContext context = listener.GetContext(); HttpListenerRequest req = context.Request; HttpListenerResponse res = context.Response; string resString = "accept"; Console.WriteLine(req.RawUrl); if (RequestEvent != null) { reqArgs = new RequestEventArgs { Request = req }; RequestEvent(this, reqArgs); resString = reqArgs.Response; } //if(resString) Encoding enc = Encoding.UTF8; byte[] buffer = enc.GetBytes(resString); res.OutputStream.Write(buffer, 0, buffer.Length); res.Close(); } listener.Close(); }
public void start() { if (listener != null) { listener.Stop(); listener.Prefixes.Clear(); } else { listener = new HttpListener(); } //string prefix = "http://localhost:8088/"; string prefix = "http://localhost:" + this.port.ToString() +"/"; //listener = new HttpListener(); listener.Prefixes.Add(prefix); // プレフィックスの登録 listener.Start(); isbusy = true; //listener.BeginGetContext(OnGetContext, listener); while (isbusy) { HttpListenerContext context = listener.GetContext(); HttpListenerRequest req = context.Request; HttpListenerResponse res = context.Response; string resString = "accept"; Console.WriteLine(req.RawUrl); if (RequestEvent != null) { reqArgs = new RequestEventArgs { Request = req }; RequestEvent(this, reqArgs); resString = reqArgs.Response; } //if(resString) Encoding enc = Encoding.UTF8; byte[] buffer = enc.GetBytes(resString); res.OutputStream.Write(buffer, 0, buffer.Length); res.Close(); } listener.Close(); }