コード例 #1
0
        public IActionResult Index(CallModel model)
        {
            // Apply input history from cookie
            var cu = ControllerUtils.From(this);

            cu.PersistInput("Uri", model, CallModel.Default.Uri);
            cu.PersistInput("Method", model, CallModel.Default.Method);
            cu.PersistInput("Body", model, CallModel.Default.Body);

            model.SampleUri = $"{Request.Scheme}://{Request.Host}/api/Dummy?a=11&b=22";

            if (!model.SkipCall)
            {
                Task <HttpResponseMessage> task = null;
                switch (model.Method)
                {
                case "(unknown)":
                case "GET":
                    task         = HTTP.GetAsync(model.Uri);
                    model.Method = "GET";
                    break;

                case "POST":
                    task = HTTP.PostAsync(model.Uri, new StringContent(model.Body));
                    break;

                default:
                    var req = new HttpRequestMessage
                    {
                        Method     = GetMethod(model.Method),
                        RequestUri = new Uri(model.Uri),
                        Content    = new StringContent(model.Body),
                    };
                    task = HTTP.SendAsync(req);
                    break;
                }
                model.Set(task);
            }
            model.SkipCall = false;
            return(View(model));
        }