Exemplo n.º 1
0
        public async Task includeUrl(TemplateScopeContext scope, string url, object options)
        {
            var scopedParams = scope.AssertOptions(nameof(includeUrl), options);

            var webReq = (HttpWebRequest)WebRequest.Create(url);

            if (scopedParams.TryGetValue("method", out object method))
            {
                webReq.Method = (string)method;
            }

            if (scopedParams.TryGetValue("contentType", out object contentType))
            {
                webReq.ContentType = (string)contentType;
            }

            if (scopedParams.TryGetValue("accept", out object accept))
            {
                webReq.Accept = (string)accept;
            }

            using (var webRes = await webReq.GetResponseAsync())
                using (var stream = webRes.GetResponseStream())
                {
                    await stream.CopyToAsync(scope.OutputStream);
                }
        }
        public HttpResult httpResult(TemplateScopeContext scope, object options)
        {
            var args = scope.AssertOptions(nameof(httpResult), options);

            return(ToHttpResult(args));
        }