DocuSign-RestApi v2-使用C#下载文档 [英] DocuSign - RestApi v2 - download document using C#
问题描述
我正在尝试通过RestAPI v2使用以下代码检索签名的文档。
I'm trying to retrieve a signed document via RestAPI v2 with below code.
url = baseURL + "/accounts/" + "3602fbe5-e11c-44de-9e04-a9fc9aa2aad6" + "/envelopes/" + envId + "/documents/combined";
HttpWebRequest request4 = (HttpWebRequest)WebRequest.Create(url);
request4.Method = "GET";
request4.Headers.Add("X-DocuSign-Authentication", authHeader);
request4.Accept = "application/pdf";
request4.ContentType = "application/json";
request4.ContentLength = 0;
HttpWebResponse webResponse4 = (HttpWebResponse)request4.GetResponse();
StreamReader objSR = new StreamReader(webResponse4.GetResponseStream());
StreamWriter objSW = new StreamWriter(@"C:\Users\reddy\Desktop\Docusign\test_" + envId + ".pdf");
objSW.Write(objSR.ReadToEnd());
objSW.Close();
objSR.Close();
使用上述代码,我可以保存PDF文件,但有些地方不对。有人可以帮我解决我的错误代码。
With above code, I'm able to save a PDF file but something is not right. Can someone help me fix my buggy code.
下载的文档:
Downloaded Document:
原始文档:
Original document:
推荐答案
选项1 :您可以简单地使用 System.Net.WebClient 类
Option 1: You can simply use the System.Net.WebClient class
string url = baseURL + "/accounts/" + accountId + "/envelopes/" + envId + "/documents/combined";
string path = @"C:\Users\reddy\Desktop\Docusign\test_" + envId + ".pdf";
using (var wc = new System.Net.WebClient())
{
wc.Headers.Add("X-DocuSign-Authentication", authHeader);
wc.DownloadFile(url, path);
}
选项2 :将输入流复制到输出FileStream
Option 2 : Copy the input stream to the output FileStream
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Headers.Add("X-DocuSign-Authentication", authHeader);
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var stream = File.Create(path))
response.GetResponseStream().CopyTo(stream);
}
选项3 :使用DocuSign C#SDK
Option 3 : Using the DocuSign C# SDK
查看完整代码< a href = https://gist.github.com/codingdawg/6039f7a919ffdfd40190d0e91041f400#file-docusigndownloadzipfile-cs-L49-L65 rel = nofollow noreferrer>此处
var envApi = new EnvelopesApi();
var docStream = envApi.GetDocument(accountId, envelopeId, "combined");
using (var stream = File.Create(filePath))
docStream.CopyTo(stream);
也请参见 answer
这篇关于DocuSign-RestApi v2-使用C#下载文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!