本文整理汇总了C#中System.Net.HttpListenerContext.SetStatusToCreated方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerContext.SetStatusToCreated方法的具体用法?C# HttpListenerContext.SetStatusToCreated怎么用?C# HttpListenerContext.SetStatusToCreated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpListenerContext
的用法示例。
在下文中一共展示了HttpListenerContext.SetStatusToCreated方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Put
private void Put(HttpListenerContext context, string docId)
{
var json = context.ReadJson();
context.SetStatusToCreated("/docs/" + docId);
var putResult = Database.Put(docId, context.GetEtag(), json, context.Request.Headers.FilterHeaders(), GetRequestTransaction(context));
context.WriteJson(putResult);
}
示例2: Respond
public override void Respond(HttpListenerContext context)
{
var match = urlMatcher.Match(context.Request.Url.LocalPath);
var filename = match.Groups[1].Value;
var etag = context.GetEtag();
switch (context.Request.HttpMethod)
{
case "GET":
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteData(attachmentAndHeaders.Data, attachmentAndHeaders.Metadata,
attachmentAndHeaders.Etag);
break;
case "PUT":
Database.PutStatic(filename, context.GetEtag(), context.Request.InputStream.ReadData(),
context.Request.Headers.FilterHeaders());
context.SetStatusToCreated("/static/" + filename);
break;
case "DELETE":
Database.DeleteStatic(filename, etag);
context.SetStatusToDeleted();
break;
}
}
示例3: 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) });
}
示例4: Respond
public override void Respond(HttpListenerContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize()));
break;
case "POST":
var json = context.ReadJson();
var id = Database.Put(null, Guid.NewGuid(), json,
context.Request.Headers.FilterHeaders(),
GetRequestTransaction(context));
context.SetStatusToCreated("/docs/" + id);
context.WriteJson(id);
break;
}
}