zoukankan      html  css  js  c++  java
  • 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(8081); //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, 0, buffer.Length);
        // You must close the output stream.
        output.Close();
    }

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

    参考文章:Embedded .NET HTTP Server

  • 相关阅读:
    1.3.9、通过权重 Weight匹配
    1.3.8、通过RemoteAddr匹配
    1.3.7、通过QueryParam匹配
    1.3.6、通过Path匹配
    1.3.5、通过Method匹配
    1.3.4、通过Host匹配
    css选择器优先级如何计算
    pm2常用命令
    前端微服务 二
    前端微服务
  • 原文地址:https://www.cnblogs.com/eastson/p/3450629.html
Copyright © 2011-2022 走看看