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


C# HttpServer.Send方法代码示例

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


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

示例1: Process

        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            var path = this.GetPath(request.Uri);
            var html = System.IO.Path.Combine(path, "index.html");
            var htm = System.IO.Path.Combine(path, "index.htm");

            if (System.IO.Directory.Exists(path) && (System.IO.File.Exists(html) || System.IO.File.Exists(htm)))
            {
                if (!request.Uri.AbsolutePath.EndsWith("/"))
                {
                    response.Redirect(request.Uri.AbsolutePath + "/");
                    return true;
                }

                response.Status = System.Net.HttpStatusCode.OK;
                response.Reason = "OK";
                response.ContentType = "text/html; charset=utf-8";

                using (var fs = System.IO.File.OpenRead(System.IO.File.Exists(html) ? html : htm))
                {
                    response.ContentLength = fs.Length;
                    response.Body = fs;
                    response.Send();
                }

                return true;
            }

            return false;
        }
开发者ID:HITSUN2015,项目名称:duplicati,代码行数:30,代码来源:IndexHtmlHandler.cs

示例2: Process

        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if ((request.Uri.AbsolutePath == "/" || request.Uri.AbsolutePath == "/index.html" || request.Uri.AbsolutePath == "/index.htm") && System.IO.File.Exists(m_defaultdoc))
            {
                response.Status = System.Net.HttpStatusCode.OK;
                response.Reason = "OK";
                response.ContentType = "text/html";

                using (var fs = System.IO.File.OpenRead(m_defaultdoc))
                {
                    response.ContentLength = fs.Length;
                    response.Body = fs;
                    response.Send();
                }

                return true;
            }

            return false;
        }
开发者ID:Berimor66,项目名称:duplicati,代码行数:20,代码来源:IndexHtmlHandler.cs

示例3: Process

        public override bool Process (HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            //We use the fake entry point /control.cgi to listen for requests
            //This ensures that the rest of the webserver can just serve plain files
            if (!request.Uri.AbsolutePath.Equals(CONTROL_HANDLER_URI, StringComparison.InvariantCultureIgnoreCase))
                return false;

            HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;

            string action = input["action"].Value ?? "";

            //Lookup the actual handler method
            ProcessSub method;
            SUPPORTED_METHODS.TryGetValue(action, out method);

            if (method == null) {
                response.Status = System.Net.HttpStatusCode.NotImplemented;
                response.Reason = "Unsupported action: " + (action == null ? "<null>" : "");
                response.Send();
            } else {
                //Default setup
                response.Status = System.Net.HttpStatusCode.OK;
                response.Reason = "OK";
                #if DEBUG
                response.ContentType = "text/plain";
                #else
                response.ContentType = "text/json";
                #endif
                using (BodyWriter bw = new BodyWriter(response, request))
                {
                    try
                    {
                        method(request, response, session, bw);
                    }
                    catch (Exception ex)
                    {
                        Program.DataConnection.LogError("", string.Format("Request for {0} gave error", action), ex);
                        Console.WriteLine(ex.ToString());

                        try
                        {
                            if (!response.HeadersSent)
                            {
                                response.Status = System.Net.HttpStatusCode.InternalServerError;
                                response.Reason = "Error";
                                response.ContentType = "text/plain";

                                bw.WriteJsonObject(new
                                {
                                    Message = ex.Message,
                                    Type = ex.GetType().Name,
                                    #if DEBUG
                                    Stacktrace = ex.ToString()
                                    #endif
                                });
                                bw.Flush();
                            }
                        }
                        catch (Exception flex)
                        {
                            Program.DataConnection.LogError("", "Reporting error gave error", flex);
                        }
                    }
                }
            }

            return true;
        }
开发者ID:HITSUN2015,项目名称:duplicati,代码行数:68,代码来源:ControlHandler.cs

示例4: DownloadBugReport

        private void DownloadBugReport(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
        {
            HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
            long id;
            long.TryParse(input["id"].Value, out id);

            var tf = Program.DataConnection.GetTempFiles().Where(x => x.ID == id).FirstOrDefault();
            if (tf == null)
            {
                ReportError(response, bw, "Invalid or missing backup id");
                return;
            }

            if (!System.IO.File.Exists(tf.Path))
            {
                ReportError(response, bw, "File is missing");
                return;
            }

            var filename = "bugreport.zip";
            using(var fs = System.IO.File.OpenRead(tf.Path))
            {
                response.ContentLength = fs.Length;
                response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", filename));
                response.ContentType = "application/octet-stream";

                bw.SetOK();
                response.SendHeaders();
                fs.CopyTo(response.Body);
                response.Send();
            }
        }
开发者ID:admz,项目名称:duplicati,代码行数:32,代码来源:ControlHandler.cs


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