ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • C# Simple-HTTP 간단한 웹서버
    Search: 카테고리 없음 카테고리 없음 2020. 7. 30. 14:38

     

    https://www.nuget.org/packages/Simple-HTTP

     

    using SimpleHttp;
    using System.Threading;
    
    namespace SimpleHttpTest1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Route.Add("/", (req, res, props) =>
                {
                    res.AsText("Welcome to Server");
                });
    
                Route.Add("/user/{id}", (req, res, props) =>
                {
                    res.AsText($"You have requested user #{props["id"]}");
                }, "POST");
    
                Route.Add("/header", (req, res, props) =>
                {
                    res.AsText($"Value of my-header is: {req.Headers["my-header"]}");
                });
    
                HttpServer.ListenAsync(
                        1337,
                        CancellationToken.None,
                        Route.OnHttpRequestAsync
                    )
                    .Wait();
            }
        }
    }

     

    댓글