// Module manager handles all modules in the server
var moduleManager = new ModuleManager();
moduleManager.Add(new BodyDecodingModule(new UrlFormattedDecoder()));
MyModule myM = new MyModule();
moduleManager.Add(myM);
// And start the server.
HttpServer _server = new HttpServer(moduleManager);
_server.Start(IPAddress.Any, 8088);
public class MyModule : IWorkerModule
{
public ModuleResult HandleRequest(IHttpContext context)
{
IRequest msg = context.Request;
if (msg.Method == "GET")
{
byte[] byContent = Encoding.UTF8.GetBytes(dictParams["echostr"]);
context.Response.Body = new MemoryStream();
context.Response.ContentType = "text/html; charset=UTF-8";
context.Response.Body.Write(byContent, 0, byContent.Length);
context.Response.Body.Position = 0;
}
else if (msg.Method == "POST")
{
if (msg.ContentLength > 0 && msg.Body != null)
{
var buff = new byte[msg.ContentLength];
msg.Body.Read(buff, 0, msg.ContentLength);
Encoding codeM = Encoding.GetEncoding("utf-8");
string strContent = codeM.GetString(buff);
OutputMessage(string.Format("Content:{0}", strContent));
}
}
return ModuleResult.Continue;
}
}
My application was crashed after received one http request. Logger as below