国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C# 控制臺或者winform程序開啟http的監聽狀態

2019-11-17 02:32:12
字體:
來源:轉載
供稿:網友

C# 控制臺或者winform程序開啟http的監聽狀態

  1 public class THttpListener  2     {  3         HttpListener listerner;  4         /// <summary>  5         ///   6         /// </summary>  7         /// <param name="

測試調用類

 1 public class TestHttp 2     { 3         THttpListener _HttpListener; 4         public TestHttp() 5         { 6             string[] strUrl = new string[] { "http://*/Test/" }; 7             _HttpListener = new THttpListener(strUrl); 8             _HttpListener.ResponseEvent += _HttpListener_ResponseEvent; 9             _HttpListener.Start();10         }11 12         void _HttpListener_ResponseEvent(System.Net.HttpListenerContext ctx)13         {14             //直接獲取數據15             Dictionary<string, string> rets = _HttpListener.getData(ctx);16             //獲取get數據17             Dictionary<string, string> retGets = _HttpListener.getData(ctx, THttpListener.DataType.Get);18             //獲取post數據19             Dictionary<string, string> retPosts = _HttpListener.getData(ctx, THttpListener.DataType.Post);20             ResponseWrite(ctx.Request.AcceptTypes[0], "Ret", ctx.Response);21         }22 23         static void ResponseWrite(string type, string msg, System.Net.HttpListenerResponse response)24         {25             //使用Writer輸出http響應代碼26             using (System.IO.StreamWriter writer = new System.IO.StreamWriter(response.OutputStream, new UTF8Encoding()))27             {28                 response.ContentType = type + ";charset=utf-8";29                 writer.WriteLine(msg);30                 writer.Close();31                 response.Close();32             }33         }34     }

當我們在服務程序或者后臺程序需要開啟對http的監聽,來獲取提交數據,但是又不能web服務器來掛在的程序,


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 方城县| 齐河县| 监利县| 长治县| 炎陵县| 莆田市| 彝良县| 崇义县| 邮箱| 连州市| 绍兴县| 长泰县| 中方县| 元谋县| 阿拉尔市| 尚志市| 固安县| 库伦旗| 汉沽区| 仁布县| 洪雅县| 武夷山市| 奈曼旗| 六安市| 平塘县| 奉贤区| 贵定县| 广宗县| 福鼎市| 巴林左旗| 唐海县| 历史| 富川| 侯马市| 邯郸市| 惠安县| 修水县| 惠水县| 车险| 宁河县| 曲麻莱县|