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的更多相关文章
随机推荐
- 【BZOJ 3669】 3669: [Noi2014]魔法森林 (动态spfa)
3669: [Noi2014]魔法森林 Description 为了得到书法大家的真传,小E同学下定决心去拜访住在魔法森林中的隐士.魔法森林可以被看成一个包含个N节点M条边的无向图,节点标号为1..N ...
- BZOJ 2049 [Sdoi2008]Cave 洞穴勘测(动态树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2049 [题目大意] 要求支持树的断边和连边,以及连接查询 [题解] LCT练习题 [代 ...
- bzoj 4428: [Nwerc2015]Debugging调试
4428: [Nwerc2015]Debugging调试 Description Your fancy debugger will not help you in this matter. There ...
- 2016.4.3 动态规划NOI专练 王老师讲课整理
1.6049:买书 总时间限制: 1000ms 内存限制: 65536kB 描述 小明手里有n元钱全部用来买书,书的价格为10元,20元,50元,100元. 问小明有多少种买书方案?(每种书可购买 ...
- Java高级架构师(一)第36节:Nginx的反向代理模块
理解Http正向代理和Http反向代理的区别 Proxy模块,最常用的proxy_pass, Proxy_pass 可以转发请求到其他的浏览器. # Nginx强项在于负载.反向.动静分离 #
- 利用tempo将json数据填充到html模板
1.下载tempo 2.使用 <!DOCTYPE html> <html> <head lang="zn-ch"> <meta chars ...
- AS3.0 效率优化
1.显示对象:1.1.静态的不需互动的图形,使用Shape对象.(eg:getSize(newShape())=236) 1.2.不需要时间轴的互动图形,使用Sprite对象.(eg:getSize( ...
- Windows命令行的使用
在介绍Windows批处命令前,我们首先来介绍Windows命令行的使用. Windows shell提供了一个黑色的框框界面,即命令行操作界面,关于命令行的作用和好处,我就不费口舌了,下面仅窥见一斑 ...
- iOS:开发常用GitHub开源项目(持续更新)
IOS开发常用GitHub开源项目(持续更新) 数据类 开源库 作者 简介 AFNetworking Mattt 网络请求库 ASIHTTPRequest pokeb 网络请求库 Alamofire ...
- Apache的Order Allow,Deny详解
Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权. 所以,最常用的是: O ...