Пример #1
0
        public Task <FileModel> RunHttpRequestReturningAttachmentImplStr(string interfaceName, string methodName, string inputParam)
        {
            var url = string.Format("/{0}/{1}", interfaceName, methodName);

            Logger.Debug(typeof(BridgeHttpRequester), "POST via iframe url={0} params={1}", url, inputParam);

            //create form post within iframe. This will download file and should put eventual error page into new window (thus not breaking singlepageapp too hard)

            var iframe = new HTMLIFrameElement();

            iframe.Style.Visibility = Visibility.Hidden;

            Document.Body.AppendChild(iframe);

            var form = new HTMLFormElement();

            form.Target = "_blank";
            form.Method = "POST";
            form.Action = url;

            form.AppendChild(new HTMLInputElement {
                Type  = InputType.Hidden,
                Name  = Magics.PostReturningFileParameterName,
                Value = inputParam
            });

            if (Toolkit.CsrfToken != null)
            {
                form.AppendChild(new HTMLInputElement {
                    Type  = InputType.Hidden,
                    Name  = Philadelphia.Common.Model.Magics.CsrfTokenFieldName,
                    Value = Toolkit.CsrfToken
                });
            }

            iframe.AppendChild(form);
            form.Submit();
            Document.Body.RemoveChild(iframe);

            return(Task.FromResult(
                       FileModel.CreateDownloadRequest(
                           url,
                           new Tuple <string, string>(
                               Magics.PostReturningFileParameterName,
                               inputParam))));
        }