0

我正在尝试编写一个 C# 程序来将我的 Appian 案例与外部电子文档记录管理系统 (EDRMS) 集成。

该程序需要下载已在 Appian 中为每个案例上传的文档,然后确保使用 Web 服务将它们上传到 EDRMS。

我编写了一个 Appian Web-api,可用于登录并检索每个案例的文档列表,因此我知道需要将文档放在 EDRMS 中的哪个位置。

可通过以下 URL [使用网络浏览器] 访问这些文档:https ://myappiansite.appiancloud.com/suite/doc/123456

如果我使用我的网络浏览器浏览到这个 URL,它会立即下载该文件。

但是,如果我尝试从我的 C# 程序以编程方式连接到此 url,当我 [尝试] 打开文件流时,我得到的是默认登录页面的一些 HTML,而不是文档的内容。

我正在编写的代码如下所示:

        HttpWebRequest MyRequest = (HttpWebRequest)WebRequest.Create("https://myappiansite.appiancloud.com/suite/doc/123456?signin=native");
        MyRequest.Timeout = 10000; // 10 seconds

        CredentialCache credentialCache = new CredentialCache();
        credentialCache.Add(new System.Uri("https://myappiansite.appiancloud.com/suite/doc/123456?signin=native"),
                            "Basic",
                            new NetworkCredential("myAppianUsername",
                                                  "myAppainPassword"));

        MyRequest.Credentials = credentialCache; 
        MyRequest.PreAuthenticate = true;

        // Get the web response
        HttpWebResponse MyResponse = (HttpWebResponse)MyRequest.GetResponse();

        if (HttpStatusCode.OK == MyResponse.StatusCode)
        {
            int chunkSize = 524288;
            using (FileStream fs = new FileStream("C:\temp\myNewFile.doc", FileMode.Create))
            {
                using (Stream MyResponseStream = MyResponse.GetResponseStream())
                {
                    BinaryReader br = new BinaryReader(MyResponseStream);
                    byte[] data;
                    Boolean lastChunk = false;

                    do
                    {
                        data = br.ReadBytes(chunkSize);
                        if (data == null || data.Length == 0 || data.Length < chunkSize)
                        {
                            lastChunk = true;
                        }
                        if (data != null)
                        {
                            fs.Write(data, 0, data.Length);
                        }
                   }
                   while (!lastChunk);
                   br.Close();
                }//using MyResponseStream
            } // Using fs
        }

但是当这段代码运行时,文档“C:\temp\myNewFile.doc”只包含我们主登录页面的 HTML。

关于为什么浏览到https://myappiansite.appiancloud.com/suite/doc/123456会下载文档的任何想法,但上面的代码只是获取登录页面的 HTML?

[请注意,用户“myAppianUsername”是非 saml 用户,而通常,用户会使用通过 SAML 连接到 AD 的帐户登录。如果我从 URL 中删除“?signin=native”,则下载的文件包含 SAML 登录的 HTML]

多谢,

大卫。

4

1 回答 1

0

我发现问题出在哪里 - 事实证明,Appian 内置了安全限制,不允许应用程序使用 URL“ https://myappiansite.appiancloud.com/suite/doc/123456 ”下载文档。我必须创建一个单独的 web-api 来做到这一点。幸运的是,Appian 提供了一个文档下载 web-api 模板/向导,可以为您生成 api。

因此,通过使用文档下载 web-api 向导生成一个名为“DownloadMyFile”的 web api,我能够使用未更改的代码,web-api 为:

https://myappiansite.appiancloud.com/suite/webapi/DownloadMyFile/12345

我必须对其进行的唯一小调整是将额外的文档类型添加到其白名单中。

于 2019-10-09T02:11:51.793 回答