MiniHttpServer
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();
}
MiniHttpServer的更多相关文章
随机推荐
- Xamarin Forms启动自带模拟器缓慢
Xamarin Forms启动自带模拟器缓慢 Xamarin Forms启动自带模拟器缓慢,在Windows 10中,Visual Studio可以使用系统自带的Hyper模拟器.但是使用时候,会长时 ...
- 通过myEclipse创建hibernate的实体类
今天有个新项目中需要使用到hibernate,刚好数据库表已经创建完毕,就顺便来总结一下通过myEclipse创建hibernate的实体类. 1..在myEclipse中选择MyEclipse Da ...
- canvas元素内容生成图片
转自https://segmentfault.com/a/1190000003853394 想要将canvas元素当前显示的内容生成为图像文件,我们首先要获取canvas中的数据,在HTML5 < ...
- Active Snake (Level Set 模型)
前沿:最近由于大论文实验的原因,需要整理几种Snake方法,以比较道路提取效果.所以今天晚上就将电脑中的一些LBF Snake代码作一下分类定义.并给出效果.以便比较. 1. 原始的LBF Snake ...
- zk常见面试题
一个客户端修改了某个节点的数据,其它客户端能够马上获取到这个最新数据吗 ZooKeeper不能确保任何客户端能够获取(即Read Request)到一样的数据,除非客户端自己要求:方法是客户端在获取数 ...
- 自动build服务器 CruiseControl.NET
<cruisecontrol xmlns:cb="urn:ccnet.config.builder"> <!-- This is your CruiseContr ...
- React个人学习笔记
元素渲染 通过 ReactDOM.render() 方法渲染页面, 可以使用 ES6 class 来定义一个组件: 如何解析HTMl里面的空格: 1. 使用空格的 unicod 编码 : \u0020 ...
- Git 学习(一)简介及安装
Git 简介及安装 Git是目前世界上最先进的分布式版本控制系统(没有之一).它的诞生也颇具传奇,Linux创始人Linus花了两周时间自己用C写了一个分布式版本控制系统,这就是Git!有兴趣的话,可 ...
- 流畅的python第三章字典和集合学习记录
什么是可散列的数据类型 如果一个对象是可散列的,那么在这个对象的生命周期中,他的散列值是不变的,而且这个对象需要实现__hash__()方法.另外可散列对象还要有__qe__()方法.这样才能跟其他键 ...
- shadow 优化
http://gamedevs.org/uploads/rendering-in-battlefield3.pdf mark 当初看过 ======= sm有两阶段 1生成sm 2采样 第一阶段的优化 ...