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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM