国产探花免费观看_亚洲丰满少妇自慰呻吟_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服務器來掛在的程序,


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 班戈县| 伊春市| 普洱| 丁青县| 大关县| 延川县| 山东省| 逊克县| 道孚县| 平泉县| 中阳县| 开原市| 德惠市| 芮城县| 晋州市| 敖汉旗| 华蓥市| 山阴县| 南溪县| 阿荣旗| 连州市| 光泽县| 台湾省| 临清市| 高清| 芦溪县| 滕州市| 汕头市| 介休市| 界首市| 赤城县| 芜湖市| 太和县| 三江| 茌平县| 洪江市| 刚察县| 儋州市| 庆安县| 广河县| 疏附县|