當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpListenerResponse.WriteJson方法代碼示例

本文整理匯總了C#中System.Net.HttpListenerResponse.WriteJson方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpListenerResponse.WriteJson方法的具體用法?C# HttpListenerResponse.WriteJson怎麽用?C# HttpListenerResponse.WriteJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Net.HttpListenerResponse的用法示例。


在下文中一共展示了HttpListenerResponse.WriteJson方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
            }
        }
開發者ID:pkmnfrk,項目名稱:loadtest,代碼行數:68,代碼來源:CnC.cs

示例2: OnStatusSpecific

        private void OnStatusSpecific(HttpListenerRequest req, HttpListenerResponse resp)
        {
            if (req.HttpMethod != "GET")
            {
                resp.Write405();
            }

            var g = req.Url.AbsolutePath.Substring(8);

            Guid job;

            if (!Guid.TryParse(g, out job) || !jobs.ContainsKey(job))
            {
                resp.Write404();
                return;
            }

            resp.WriteJson(new Result(jobs[job]));
        }
開發者ID:pkmnfrk,項目名稱:loadtest,代碼行數:19,代碼來源:CnC.cs

示例3: StatusGeneral

        private void StatusGeneral(HttpListenerRequest req, HttpListenerResponse resp)
        {
            IList<Guid> queued, comp;

            lock (jobQueue)
            {
                queued = jobQueue.Select(j => j.Tag).ToList();
            }

            lock (completed)
            {
                comp = completed.Select(c => c.Tag).ToList();
            }

            var cur = current;

            resp.WriteJson(new
            {
                enqueued = queued,
                current = cur != null ? (Guid?)cur.Tag : (Guid?)null,
                completed = comp
            });
        }
開發者ID:pkmnfrk,項目名稱:loadtest,代碼行數:23,代碼來源:CnC.cs

示例4: OnGetSlave

 private void OnGetSlave(HttpListenerRequest req, HttpListenerResponse res)
 {
     res.WriteJson(slaves);
 }
開發者ID:pkmnfrk,項目名稱:loadtest,代碼行數:4,代碼來源:Server.cs


注:本文中的System.Net.HttpListenerResponse.WriteJson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。