C# 实现简单的http服务器

通过C# 来简单实现一个http服务器,来大概了解http get和post数据的大概方式。

简单实现post数据 ContentType其中=的三种方式。

 

  private void handleContentType(HttpListenerContext context)
       {
         
           if (context.Request.ContentType.Contains("multipart/form-data"))
           {
               handlePostMultipart(context);
           }
           else if (context.Request.ContentType.Contains("application/x-www-form-urlencoded"))
           {

               handleFormUrlencoded(context);
           }


           else if (context.Request.ContentType.Contains("application/json"))
           {

               handleJson(context);
           }

           else
           {
               new processSendClient(context).write("post请求的数据:" + context.Request.ContentType);
           }

          

       }

 

 

 

 

 

 

 

 

 

 

vs2013下编译通过。

https://files-cdn.cnblogs.com/files/gogosai/httpServer.zip?t=1648293903

 

posted @ 2022-03-26 19:29  fujiwara_sai  阅读(1713)  评论(0编辑  收藏  举报