当前位置: 首页>>代码示例>>C#>>正文


C# Net.HttpListenerRequest类代码示例

本文整理汇总了C#中System.Net.HttpListenerRequest的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerRequest类的具体用法?C# HttpListenerRequest怎么用?C# HttpListenerRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpListenerRequest类属于System.Net命名空间,在下文中一共展示了HttpListenerRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Handle

        public override IResponseFormatter Handle(HttpListenerRequest request)
        {
            var transportManager = Singleton<TransportManager>.instance;
            if (transportManager == null)
                return JsonResponse(new Dictionary<string, List<PublicTransportLine>>());

            var lines = transportManager.m_lines.m_buffer.ToList();
            if (lines == null)
                return JsonResponse(new Dictionary<string, List<PublicTransportLine>>());
            var busLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportBus);
            var metroLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportMetro);
            var trainLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportTrain);
            var shipLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportShip);
            var planeLines = lines.Where(x => x.Info.m_class.m_subService == ItemClass.SubService.PublicTransportPlane);

            Dictionary<string, List<PublicTransportLine>> allTransportLines = new Dictionary<string, List<PublicTransportLine>>()
            {
                {"BusLines", MakeLinesModels(busLines)},
                {"MetroLines", MakeLinesModels(metroLines)},
                {"TrainLines", MakeLinesModels(trainLines)},
                {"ShipLines", MakeLinesModels(shipLines)},
                {"PlaneLines", MakeLinesModels(planeLines)},
            };

            return JsonResponse(allTransportLines);
        }
开发者ID:gramx,项目名称:CityWebServerExtension,代码行数:26,代码来源:TransportRequestHandler.cs

示例2: RestRequest

        public RestRequest(HttpListenerRequest request)
        {
            this.HttpMethod = request.HttpMethod;
            this.Url = request.Url;
            this.RESTModuleName = request.Url.Segments[1].Replace("/", "");
            this.RESTMethodName = request.Url.Segments[2].Replace("/", "");
            this.RESTMethodParameters = request.QueryString;
            this.Cookies = request.Cookies;

            if (request.HasEntityBody)
            {
                Encoding encoding = request.ContentEncoding;

                using (var bodyStream = request.InputStream)
                using (var streamReader = new StreamReader(bodyStream, encoding))
                {
                    if (request.ContentType != null)
                    {
                        this.ContentType = request.ContentType;
                    }

                    this.ContentLength = request.ContentLength64;
                    this.Body = streamReader.ReadToEnd();
                }

                if (this.HttpMethod == "POST" && this.ContentType == "application/x-www-form-urlencoded")
                {
                    this.RESTMethodParameters = ParseQueryString(System.Uri.UnescapeDataString(this.Body));
                }
            }
        }
开发者ID:ltloibrights,项目名称:AsyncRPG,代码行数:31,代码来源:RestRequest.cs

示例3: WebserviceRequest

 public WebserviceRequest(string url, string rawdata, HttpListenerRequest request)
 {
     URL = url;
     RawData = rawdata;
     RawRequest = request;
     ParseData();
 }
开发者ID:RickardPettersson,项目名称:MobileBFAdmin,代码行数:7,代码来源:WebserviceRequest.cs

示例4: Handle

        public override IResponseFormatter Handle(HttpListenerRequest request)
        {
            // TODO: Customize request handling.
            var messages = _chirpRetriever.Messages;

            return JsonResponse(messages);
        }
开发者ID:gramx,项目名称:CityWebServer,代码行数:7,代码来源:MessageRequestHandler.cs

示例5: Handle

        public override IResponseFormatter Handle(HttpListenerRequest request)
        {
            var buildingManager = Singleton<BuildingManager>.instance;

            if (request.Url.AbsolutePath.StartsWith("/Building/List"))
            {
                List<ushort> buildingIDs = new List<ushort>();

                var len = buildingManager.m_buildings.m_buffer.Length;
                for (ushort i = 0; i < len; i++)
                {
                    if (buildingManager.m_buildings.m_buffer[i].m_flags == Building.Flags.None) { continue; }

                    buildingIDs.Add(i);
                }

                return JsonResponse(buildingIDs);
            }

            foreach (var building in buildingManager.m_buildings.m_buffer)
            {
                if (building.m_flags == Building.Flags.None) { continue; }

                // TODO: Something with Buildings.
            }

            return JsonResponse("");
        }
开发者ID:gramx,项目名称:CityWebServer,代码行数:28,代码来源:BuildingRequestHandler.cs

示例6: GetFileHandler

        static void GetFileHandler(HttpListenerRequest request, HttpListenerResponse response)
        {
            var query = request.QueryString;
            string targetLocation = query["target"];
            Log ("GetFile: " + targetLocation + "...");

            if(File.Exists(targetLocation))
            {
                try
                {
                    using(var inStream = File.OpenRead(targetLocation))
                    {
                        response.StatusCode = 200;
                        response.ContentType = "application/octet-stream";
                        CopyStream(inStream, response.OutputStream);
                    }
                }
                catch(Exception e)
                {
                    Log (e.Message);
                    response.StatusCode = 501;
                }
            }
            else
            {
                response.StatusCode = 501;
                Log ("File doesn't exist");
            }
        }
开发者ID:bizarrefish,项目名称:TestVisor,代码行数:29,代码来源:VMAgentServer.cs

示例7: HttpRequest

 /// <summary>
 /// Creates a new instance of HttpRequest
 /// </summary>
 /// <param name="Client">The HttpClient creating this response</param>
 public HttpRequest(HttpListenerRequest Request, HttpClient Client)
 {
     // Create a better QueryString object
     this.QueryString = Request.QueryString.Cast<string>().ToDictionary(p => p, p => Request.QueryString[p]);
     this.Request = Request;
     this.Client = Client;
 }
开发者ID:BF2Statistics,项目名称:ControlCenter,代码行数:11,代码来源:HttpRequest.cs

示例8: HttpListenerRequestWrapper

 public HttpListenerRequestWrapper(HttpListenerRequest httpListenerRequest)
 {
     _httpListenerRequest = httpListenerRequest;
     _qs = new NameValueCollection(httpListenerRequest.QueryString);
     _headers = new NameValueCollection(httpListenerRequest.Headers);
     _cookies = new CookieCollectionWrapper(_httpListenerRequest.Cookies);
 }
开发者ID:ninjaAB,项目名称:SignalR,代码行数:7,代码来源:HttpListenerRequestWrapper.cs

示例9: RespondWithNotFound

 private void RespondWithNotFound(HttpListenerRequest request, HttpListenerResponse response)
 {
     _log.DebugFormat("Responded with 404 Not Found for url {0}", request.Url);
     response.StatusCode = 404;
     response.StatusDescription = "Not Found";
     response.OutputStream.Close();
 }
开发者ID:MatteS75,项目名称:Qupla,代码行数:7,代码来源:WebServer.cs

示例10: Find

 public RouteHandler Find(HttpListenerRequest request, out UriTemplateMatch templateMatch)
 {
     var reqId = request.HttpMethod + ":" + request.Url.LocalPath;
     KeyValuePair<RouteHandler, Uri> rh;
     if (Cache.TryGetValue(reqId, out rh))
     {
         templateMatch = rh.Key.Template.Match(rh.Value, request.Url);
         return rh.Key;
     }
     templateMatch = null;
     List<RouteHandler> handlers;
     if (!MethodRoutes.TryGetValue(request.HttpMethod, out handlers))
         return null;
     var reqUrl = request.Url;
     var url = reqUrl.ToString();
     var baseAddr = new Uri(url.Substring(0, url.Length - request.RawUrl.Length));
     foreach (var h in handlers)
     {
         var match = h.Template.Match(baseAddr, reqUrl);
         if (match != null)
         {
             templateMatch = match;
             Cache.TryAdd(reqId, new KeyValuePair<RouteHandler, Uri>(h, baseAddr));
             return h;
         }
     }
     return null;
 }
开发者ID:nutrija,项目名称:revenj,代码行数:28,代码来源:Routes.cs

示例11: RequestHandler

        void RequestHandler(HttpListenerRequest req, HttpListenerResponse res)
        {
            Console.WriteLine("[RequestHandler: req.url=" + req.Url.ToString());

            if (req.Url.AbsolutePath == "/cmd/record/start") {
                Record.Start(req, res);
            }
            else if (req.Url.AbsolutePath == "/cmd/record/stop") {
                Record.Stop(req, res);
            }
            else if (req.Url.AbsolutePath == "/cmd/livingcast/start") {
                LivingCast.Start(req, res);
            }
            else if (req.Url.AbsolutePath == "/cmd/livingcast/stop") {
                LivingCast.Stop(req, res);
            }
            else {
                res.StatusCode = 404;
                res.ContentType = "text/plain";

                try
                {
                    StreamWriter sw = new StreamWriter(res.OutputStream);
                    sw.WriteLine("NOT supported command: " + req.Url.AbsolutePath);
                    sw.Close();
                }
                catch { }
            }
        }
开发者ID:FihlaTV,项目名称:conference,代码行数:29,代码来源:Server.cs

示例12: Handle

        /// <summary>
        /// 处理程序
        /// </summary>
        /// <param name="request">请求上下文</param>
        public string Handle(HttpListenerRequest requestContext)
        {
            var command = requestContext.QueryString["command"];

            //byte[] fileBuffer = new byte[1024 * 32];

            //using (MemoryStream ms = new MemoryStream())
            //{
            //    while (true)
            //    {
            //        int read = requestContext.InputStream.Read(fileBuffer, 0, fileBuffer.Length);
            //        if (read <= 0)
            //        {
            //            FileStream fs = new FileStream("C:\\111.xlsx", FileMode.OpenOrCreate);
            //            byte[] buff = ms.ToArray();
            //            fs.Write(buff, 0, buff.Length);
            //            fs.Close();
            //            break;

            //        }
            //        ms.Write(fileBuffer, 0, read);
            //    }
            //}
            return "200";
        }
开发者ID:cnalwaysroad,项目名称:Urge,代码行数:29,代码来源:WithCommand.cs

示例13: HandleCreateAccount

        private static string HandleCreateAccount(HttpServer server, HttpListenerRequest request, Dictionary<string, string> parameters)
        {
            if (!parameters.ContainsKey("username")) throw new Exception("Missing username.");
            if (!parameters.ContainsKey("password")) throw new Exception("Missing password.");

            string username = parameters["username"];
            string password = parameters["password"];

            if (Databases.AccountTable.Count(a => a.Username.ToLower() == username.ToLower()) > 0) return JsonEncode("Username already in use!");

            System.Text.RegularExpressions.Regex invalidCharacterRegex = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]");
            if (invalidCharacterRegex.IsMatch(username)) return JsonEncode("Invalid characters detected in username!");

            Random getrandom = new Random();
            String token = getrandom.Next(10000000, 99999999).ToString();
            AccountEntry entry = new AccountEntry();
            entry.Index = Databases.AccountTable.GenerateIndex();
            entry.Username = username;
            entry.Password = password;
            entry.Verifier = "";
            entry.Salt = "";
            entry.RTW_Points = 0;
            entry.IsAdmin = 0;
            entry.IsBanned = 0;
            entry.InUse = 0;
            entry.extrn_login = 0;
            entry.CanHostDistrict = 1;
            entry.Token = token;
            Databases.AccountTable.Add(entry);

            Log.Succes("HTTP", "Successfully created account '" + username + "'");
            return JsonEncode("Account created!\n\nYour token is: " + token + ".\nCopy and paste given token in \"_rtoken.id\" file and put it in the same folder where your \"APB.exe\" is located.");
        }
开发者ID:fiki574,项目名称:rAPB,代码行数:33,代码来源:HttpServer.Handlers.cs

示例14: HttpRequest

        public HttpRequest(HttpListenerRequest listenerRequest)
        {
            _request = listenerRequest;
            _formData = new FormData(listenerRequest);

            LoadFormData();
        }
开发者ID:randacc,项目名称:hdkn,代码行数:7,代码来源:HttpRequest.cs

示例15: HttpListenerRequestAdapter

	    public HttpListenerRequestAdapter(HttpListenerRequest request)
		{
			this.request = request;
		    this.queryString = System.Web.HttpUtility.ParseQueryString(Uri.UnescapeDataString(request.Url.Query));
	        Url = this.request.Url;
	        RawUrl = this.request.RawUrl;
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:7,代码来源:HttpListenerRequestAdapter.cs


注:本文中的System.Net.HttpListenerRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。