我正在尝试编写一个C#程序,以便将我的Appian案例与外部电子文档记录管理系统(EDRMS)集成。
该程序需要下载在Appian中为每个病例上传的文档,然后确保使用web服务将它们上传到EDRMS。
我已经编写了一个Appian Web-api,我可以使用它登录并检索每个案例的文档列表,因此我知道需要将文档放在EDRMS中的什么位置。
这些文档可以使用如下网址的web浏览器进行访问:https://myappiansite.appiancloud.com/suite/doc/123456
如果我使用web浏览器浏览到此URL,它会立即下载该文件。
然而,如果我试图从我的C#程序以编程方式连接到这个url,当我试图打开文件流时,我得到的是一些默认登录页面的超文本标记语言,而不是文档的内容。
我正在编写的代码如下所示:
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“只包含我们的主登录页面的超文本标记语言。
你有没有想过为什么浏览https://myappiansite.appiancloud.com/suite/doc/123456会下载文档,但上面的代码只得到了登录页面的超文本标记语言?
请注意,用户"myAppianUsername“是非myAppianUsername用户,而通常情况下,用户将使用通过SAML连接到AD的帐户登录。如果我从URL中删除"?signin=native“,那么下载的文件就包含了用于SAML登录的超文本标记语言
谢谢你,
大卫。
发布于 2019-10-09 10:11:52
我找出了问题所在--原来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
我唯一需要做的小调整就是将额外的文档类型添加到它的白名单中。
https://stackoverflow.com/questions/58281244
复制相似问题