Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 试图使用C和web api访问Appian文档';s_C#_Appian - Fatal编程技术网

C# 试图使用C和web api访问Appian文档';s

C# 试图使用C和web api访问Appian文档';s,c#,appian,C#,Appian,我正试图编写一个C#程序,将我的Appian案例与外部电子文档记录管理系统(EDRMS)集成 程序需要下载在Appian中为每个案例上传的文档,然后确保使用web服务将其上传到EDRM 我已经编写了一个Appian Web api,可以用来登录和检索每个案例的文档列表,所以我知道需要将文档放在EDRM中的什么位置 可通过如下URL[使用web浏览器]访问文档: 如果我使用web浏览器浏览到此URL,它会立即下载该文件 但是,如果我试图从我的C#程序以编程方式连接到此url,当我[尝试]打开文件流

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

程序需要下载在Appian中为每个案例上传的文档,然后确保使用web服务将其上传到EDRM

我已经编写了一个Appian Web api,可以用来登录和检索每个案例的文档列表,所以我知道需要将文档放在EDRM中的什么位置

可通过如下URL[使用web浏览器]访问文档:

如果我使用web浏览器浏览到此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
        }
HttpWebRequest MyRequest=(HttpWebRequest)WebRequest.Create(“https://myappiansite.appiancloud.com/suite/doc/123456?signin=native");
MyRequest.Timeout=10000;//10秒
CredentialCache CredentialCache=新的CredentialCache();
credentialCache.Add(新的System.Uri(“https://myappiansite.appiancloud.com/suite/doc/123456?signin=native"),
“基本”,
新网络凭据(“myAppianUsername”,
“myAppainPassword”);
MyRequest.Credentials=credentialCache;
MyRequest.PreAuthenticate=true;
//获取web响应
HttpWebResponse MyResponse=(HttpWebResponse)MyRequest.GetResponse();
if(HttpStatusCode.OK==MyResponse.StatusCode)
{
int chunkSize=524288;
使用(FileStream fs=newfilestream(“C:\temp\myNewFile.doc”,FileMode.Create))
{
使用(Stream MyResponseStream=MyResponse.GetResponseStream())
{
BinaryReader br=新的BinaryReader(MyResponseStream);
字节[]数据;
布尔值=false;
做
{
data=br.ReadBytes(chunkSize);
if(data==null | | data.Length==0 | | data.Length
但是当代码运行时,文档“C:\temp\myNewFile.doc”只包含我们的主登录页的HTML

有没有想过为什么浏览到会下载文档,但上面的代码只会得到登录页的HTML

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

谢谢你,好几堆


David。

我发现了问题所在-事实证明,Appian内置了安全限制,不允许应用程序使用url“”下载文档。为此,我必须创建一个单独的web api。幸运的是,Appian提供了一个文档下载web api模板/向导,可以为您生成api

因此,通过使用文档下载web api向导生成一个名为“DownloadMyFile”的web api,我可以不加更改地使用代码,web api为:

我唯一需要做的小调整就是在白名单中添加额外的文档类型