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


C# HttpListenerContext.Write方法代码示例

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


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

示例1: Put

 private void Put(HttpListenerContext context, string index)
 {
     var data = context.ReadJsonObject<IndexDefinition>();
     if (data.Map == null)
     {
         context.SetStatusToBadRequest();
         context.Write("Expected json document with 'Map' property");
         return;
     }
     context.SetStatusToCreated("/indexes/" + index);
     context.WriteJson(new { index = Database.PutIndex(index, data) });
 }
开发者ID:torkelo,项目名称:ravendb,代码行数:12,代码来源:Index.cs

示例2: HandleRequest

        private void HandleRequest(HttpListenerContext ctx)
        {
            if (AssertSecurityRights(ctx) == false)
                return;

            foreach (var requestResponder in requestResponders)
            {
                if (requestResponder.WillRespond(ctx))
                {
                    requestResponder.Respond(ctx);
                    return;
                }
            }
            ctx.SetStatusToBadRequest();
            ctx.Write(
                @"
            <html>
            <body>
            <h1>Could not figure out what to do</h1>
            <p>Your request didn't match anything that Raven knows to do, sorry...</p>
            </body>
            </html>
            ");
        }
开发者ID:torkelo,项目名称:ravendb,代码行数:24,代码来源:HttpServer.cs

示例3: HandleActualRequest

        private void HandleActualRequest(HttpListenerContext context)
        {
            string matchUrl = context.Request.Url.AbsolutePath.Trim().ToLower();

            Match match = FilesMatcher.Match(matchUrl);

            if (match.Success)
            {
                string recordNumber = match.Groups["record"].Value;
                string filePath = null;

                try
                {
                    using (var trimService = new TrimAttachmentRetriever(trimServer, trimDatasetId))
                    {
                        filePath = trimService.GetTrimAttachmentPath(long.Parse(recordNumber));
                        if (filePath == null)
                        {
                            context.SetStatusToNotFound();
                            return;
                        }
                        context.WriteEmbeddedFile(filePath, trimService.FileName, trimService.MimeType);
                    }
                }
                finally
                {
                    if (filePath != null)
                    {
                        File.Delete(filePath);
                    }
                }
            }
            else
            {
                string lastUpdateString = context.Request.QueryString.Get("from");
                DateTime lastUpdated;
                if (!DateTime.TryParseExact(lastUpdateString, LastUpdateFormat, CultureInfo.CurrentCulture,
                                       DateTimeStyles.AssumeLocal,
                                       out lastUpdated))
                {
                    lastUpdated = DateTime.MinValue;
                }

                using (var trimService = new TrimRecordsRetriever(trimServer, trimDatasetId))
                {
                    var records = trimService.RetrieveRecords(lastUpdated).ToList();
                    context.Write(JsonConvert.SerializeObject(new
                                                                {
                                                                    Records = records,
                                                                    FromDate = trimService.LastRecordUpdatedDate == null ? null : trimService.LastRecordUpdatedDate.Value.ToString(LastUpdateFormat)
                                                                }));
                }
                context.Response.ContentType = "application/json";
            }

            context.Response.StatusCode = 200;
            context.Response.StatusDescription = "OK";
        }
开发者ID:johnsimons,项目名称:TrimWebService,代码行数:58,代码来源:TrimWebService.cs


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