zoukankan      html  css  js  c++  java
  • 程序中内嵌Http服务的实现原型

    适用场景参考陈硕的《构建易于维护的分布式程序
    static void Main(string[] args)
            {
                
    //查看方式 http://127.0.0.1:8003/?name=TomAndJerry

                
    using (HttpListener listerner = new HttpListener())
                {
                    listerner.AuthenticationSchemes 
    = AuthenticationSchemes.Anonymous; //指定身份验证 Anonymous匿名访问
                    listerner.Prefixes.Add("http://127.0.0.1:8003/");
                    listerner.Start();
                    
    while (true)
                    {
                        HttpListenerContext ctx 
    = listerner.GetContext();
                        ctx.Response.StatusCode 
    = 200;//设置返回给客服端http状态代码
                        using (StreamWriter writer = new StreamWriter(ctx.Response.OutputStream))
                        {                                             
                            writer.WriteLine(
    "<html><head><title>The WebServer Test</title></head><body>{0}</body></html>",ctx.Request.QueryString["name"]); //封装的时候此处做事件判断将ctx.Request作参数传递出去即可
                            writer.Close();
                            ctx.Response.Close();
                        }
                    }
                }
            }
  • 相关阅读:
    React: React的组件状态机制
    React: React的复合组件
    JavaScript:ES6的新特性
    React: 研究React的组件化
    React: 认识React
    CSS:CSS弹性盒子布局 Flexible Box
    iOS:应用程序扩展开发之Today扩展(Today Extesnsion)
    《逆向工程核心原理》
    《左手数据,右手图表》
    《设计模式之禅(第2版)》
  • 原文地址:https://www.cnblogs.com/jiang_zheng/p/InnerHttpService.html
Copyright © 2011-2022 走看看