Mini HTTP Server which can be embed in EXE, Writen in C#(.net framework 2.0).

HTTP request dispatch/route, you can register the handlers for a specific url. Url match using start with in order, so that register the more specific in first. For example:

server.RegisterHandler("/index/1", FirstIndexHandler);
server.RegisterHandler("/index", GeneralIndexHandler);

When url request be handled, stop propagation. That's when we requst the "/index/1", and it's handle already. GeneralIndexHandler will NOT execute.

Usage

using Jatsz.MiniHttpServer;

MiniHttpServer server = new MiniHttpServer(); //start http server on port of 8081

//register the handler(s) and start the server
server.RegisterHandler("/index", IndexHandler);
server.Start(); void IndexHandler(object sender, ContextEventArgs e)
{
string responseString = string.Format("<HTML><BODY> Hello world! {0}</BODY></HTML>", DateTime.Now); // Obtain a response object.
HttpListenerResponse response = e.Context.Response;
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
// Get a response stream and write the response to it.
response.ContentLength64 = buffer.Length;
System.IO.Stream output = response.OutputStream;
output.Write(buffer, , buffer.Length);
// You must close the output stream.
output.Close();
}

项目主页:https://github.com/jatsz/MiniHttpServer

参考文章:Embedded .NET HTTP Server

MiniHttpServer的更多相关文章

随机推荐

  1. 多协议注入工具t50

    多协议注入工具t50   t50是Kali Linux自带的一款网络数据包注入工具.该工具支持15种协议,不仅涵盖常规协议(ICMP.TCP.UDP),还涵盖基础协议和路由协议(GRE.IPSec.R ...

  2. Xamarin Android SDK无法更新的解决办法

    Xamarin Android SDK无法更新的解决办法   Xamarin Android SDK无法更新的解决办法,更新时候,提示警告信息:A folder failed to be moved. ...

  3. [JSOI2017]原力(分块+map(hash))

    题目描述 一个原力网络可以看成是一个可能存在重边但没有自环的无向图.每条边有一种属性和一个权值.属性可能是R.G.B三种当中的一种,代表这条边上 原力的类型.权值是一个正整数,代表这条边上的原力强度. ...

  4. [BZOJ4710][JSOI2011]分特产(组合数+容斥原理)

    4710: [Jsoi2011]分特产 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 395  Solved: 262[Submit][Status] ...

  5. BZOJ 3676 [Apio2014]回文串(回文树)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3676 [题目大意] 考虑一个只包含小写拉丁字母的字符串s. 我们定义s的一个子串t的& ...

  6. [ARC103F]Distance Sums

    题意:有一棵树,对于每个点$i$,给出了它到其他点的距离和$i$,现在要还原这棵树,保证$d_i$两两不同 一个点从$u$移到相邻节点$v$时,若删掉$(u,v)$后$u$这边的连通块大小为$siz_ ...

  7. CSS3新增

    1 CSS3 的选择器 1.1 基本选择器 tagName .className #idName * slector,selector,selector 1.2 层级选择器 selector1 sel ...

  8. Codeforces Round #127 (Div. 1) B. Guess That Car! 扫描线

    B. Guess That Car! 题目连接: http://codeforces.com/contest/201/problem/B Description A widely known amon ...

  9. MATLAB/Octave warning: mx_el_eq: automatic broadcasting operation applied 错误分析

    在进行对一个mXn的矩阵与mX1的矩阵进行==比较时,原意是想让mXn的矩阵的每一行分别与mX1的矩阵每一行进行比较,得到的结果虽然是对的,但会报一个warning: mx_el_eq: automa ...

  10. 使用 Google Code Prettify 实现代码高亮

    今天这篇文章主要讲述使用 google-code-prettify 来实现代码的高亮显示,以前我使用 highlight.js 来实现文章中代码的高亮显示. prettify 非常小巧且配置简单,使用 ...