本文整理汇总了C#中System.Net.HttpListenerResponse.Write400方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerResponse.Write400方法的具体用法?C# HttpListenerResponse.Write400怎么用?C# HttpListenerResponse.Write400使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpListenerResponse
的用法示例。
在下文中一共展示了HttpListenerResponse.Write400方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnStart
private void OnStart(HttpListenerRequest req, HttpListenerResponse resp)
{
if (req.HttpMethod != "POST")
{
resp.Write405();
return;
}
if (!req.HasEntityBody)
{
resp.Write400();
return;
}
CnCStartRequest args;
using (var ist = new StreamReader(req.InputStream))
{
var body = ist.ReadToEnd();
args = body.FromJson<CnCStartRequest>();
}
if (args.job == Guid.Empty)
{
args.job = Guid.NewGuid();
}
if (args.job == Guid.Empty || jobs.ContainsKey(args.job))
{
resp.Write400();
return;
}
if (args.type == "http")
{
if (args.http == null)
{
resp.Write400();
return;
}
args.http.Tag = args.job;
var http = new HttpLoader(args.http);
jobs[args.job] = http;
lock (jobQueue)
{
jobQueue.Enqueue(http);
}
workerSignal.Set();
//speculatively wait a few seconds, in case the job is done real quick like
Thread.Sleep(2000);
resp.WriteJson(new
{
Location = "/status/" + args.job,
Data = new Result(http)
}, http.Status == Status.Complete ? 200 : 202);
}
else
{
resp.Write400();
return;
}
}