// 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
My code as below
Method:GET/ContentEncoding:/ContentLength:0 ProtocolVersion:HTTP/1.0/KeepAlive:True/ContentType: Uri AbsoluteUri:http://58.215.164.183/?signature=1dfea26808d632903549c69d78558fce1c418405&echostr=5867553698596935317×tamp=1365661332&nonce=1366146317/AbsolutePath://Host:58.215.164.183/Port:80 QueryString/Name:signature/Value:1dfea26808d632903549c69d78558fce1c418405 QueryString/Name:echostr/Value:5867553698596935317 QueryString/Name:timestamp/Value:1365661332 QueryString/Name:nonce/Value:1366146317 Headers/Name:User-Agent/Value:Mozilla/4.0 Headers/Name:Accept/Value:/ Headers/Name:Host/Value:58.215.164.183 Headers/Name:Pragma/Value:no-cache Headers/Name:Connection/Value:Keep-Alive