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


C# HttpListenerResponse.WriteResponse方法代码示例

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


在下文中一共展示了HttpListenerResponse.WriteResponse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleGet

        public void HandleGet(HttpListenerRequest request, HttpListenerResponse response)
        {
            string queryString = request.Url.Query;
            var queryParts = Server.ParseQueryString(queryString);

            string presetName = queryParts.GetFirstValue("preset");

            if (string.IsNullOrEmpty(presetName))
            {
                response.StatusCode = 200;
                response.WriteResponse(presets.GetAll());
            }
            else
            {
                string result = presets.Get(presetName);
                if (result == null)
                {
                    response.StatusCode = 404;
                    response.WriteResponse("No such preset has been registered");
                }
                else
                {
                    response.StatusCode = 200;
                    response.WriteResponse(result);
                }
            }
        }
开发者ID:cchamplin,项目名称:FFRest,代码行数:27,代码来源:PresetHandler.cs

示例2: HandleGet

        public void HandleGet(HttpListenerRequest request, HttpListenerResponse response)
        {
            try
            {
                string path = request.Url.AbsolutePath;
                if (path.Length < 9)
                {
                    response.StatusCode = 404;
                    response.WriteResponse("Thumbnail not found");
                    return;
                }
                string file = path.Substring(8);
                if (string.IsNullOrEmpty(file))
                {
                    response.StatusCode = 404;
                    response.WriteResponse("Thumbnail not found");
                    return;
                }
                // Ensure format matches thumbnail-identifier_x.jpg
                var match = Regex.Match(file, "^thumbnail-([a-zA-Z0-9_-]+)_[0-9]+\\.jpg$");
                if (!match.Success)
                {
                    response.StatusCode = 404;
                    response.WriteResponse("Thumbnail not found");
                    return;
                }
                var jobID = match.Groups[1].Value;
                string filePath = FFRest.config["workingdir"] + Path.DirectorySeparatorChar + jobID + Path.DirectorySeparatorChar + file;
                if (!File.Exists(filePath))
                {
                    response.StatusCode = 404;
                    response.WriteResponse("Thumbnail not found");
                    return;
                }
                response.StatusCode = 200;

                FileInfo fi = new FileInfo(filePath);
                response.ContentLength64 = fi.Length;
                response.ContentType = Utility.GetMime(fi.Extension);
                using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Utility.CopyStream(fs, response.OutputStream);
                }
                response.OutputStream.Flush();
                response.OutputStream.Close();
            }
            catch (Exception ex)
            {
                log.Error("Failed to process thumb request", ex);
            }
        }
开发者ID:cchamplin,项目名称:FFRest,代码行数:51,代码来源:ThumbnailHandler.cs

示例3: HandlePost

        public void HandlePost(HttpListenerRequest request, HttpListenerResponse response, Server.RequestData data)
        {
            var presetName = data.PostParameters.GetFirstValue("preset");
            var value = data.PostParameters.GetFirstValue("value");

            if (string.IsNullOrEmpty(presetName))
            {
                response.StatusCode = 400;
                response.WriteResponse("Missing preset name");
                return;
            }
            if (string.IsNullOrEmpty(value))
            {
                response.StatusCode = 400;
                response.WriteResponse("Missing preset value");
                return;
            }

            // TODO do we need to do filtering on this value?
            presets.Add(presetName, value);
            response.WriteResponse(200, "Preset added");
        }
开发者ID:cchamplin,项目名称:FFRest,代码行数:22,代码来源:PresetHandler.cs

示例4: HandleGet

 public void HandleGet(HttpListenerRequest request, HttpListenerResponse response)
 {
     try
     {
         StringBuilder bld = new StringBuilder();
         bld.Append("Total Jobs: " + totalJobs + "\n");
         bld.Append("Total Files Transcoded: " + totalFilesTranscoded + "\n");
         bld.Append("Active: " + runningJobs + "\n");
         response.StatusCode = 200;
         response.WriteResponse(bld.ToString());
     }
     catch (Exception ex)
     {
         log.Error("Stats Request Exception Occured", ex);
     }
        // return new Httpd.HttpResponse(200,bld.ToString());
 }
开发者ID:cchamplin,项目名称:FFRest,代码行数:17,代码来源:Stats.cs

示例5: HandlePost

 public void HandlePost(HttpListenerRequest request, HttpListenerResponse response, Server.RequestData data)
 {
     response.StatusCode = 400;
     response.WriteResponse("Bad Request");
     //return new Httpd.HttpResponse(400, "Bad Request");
 }
开发者ID:cchamplin,项目名称:FFRest,代码行数:6,代码来源:Stats.cs

示例6: HandlePost

 public void HandlePost(HttpListenerRequest request, HttpListenerResponse response, Server.RequestData data)
 {
     response.StatusCode = 404;
     response.WriteResponse("404 Page Not Found");
 }
开发者ID:cchamplin,项目名称:FFRest,代码行数:5,代码来源:ThumbnailHandler.cs

示例7: HandleGet

 public void HandleGet(HttpListenerRequest request, HttpListenerResponse response)
 {
     response.StatusCode = 404;
     response.WriteResponse("404 Page Not Found");
 }
开发者ID:cchamplin,项目名称:FFRest,代码行数:5,代码来源:404Handler.cs


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