2

我正在尝试将文档上传到此Adob​​eSign API 端点

虽然我找到了一种使用RestSharp RestClient成功完成此操作的方法,但代码如下:

var client = new RestClient("https://api.na2.echosign.com/api/rest/v6/transientDocuments");
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer MyIntegratorKey");

            var bytes = Convert.FromBase64String(base64Document);
            var contents = new MemoryStream(bytes);
            request.Files.Add(new FileParameter
            {
                Name = "File",
                Writer = (s) =>
                {
                    var stream = contents;
                    stream.CopyTo(s);
                    stream.Dispose();
                },
                FileName = "Test2.pdf",
                ContentType = null,
                ContentLength = bytes.Length
            });
            IRestResponse response = client.Execute(request);
            Console.WriteLine(response.Content);

我在尝试使用.NET HttpClient时遇到问题。我下面的代码成功上传了文档(Adobe 返回的 HTTP 201),但是当签名者打开它时,文档完全搞砸了。

.NET HttpClient 不支持文件上传吗?我的直播有什么问题吗? 先感谢您

using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse("Bearer IntegratorKey");
        using (var content = new MultipartFormDataContent())
        {
            content.Add(new StreamContent(new MemoryStream(Convert.FromBase64String(document.EmbeddedContent))), "File", "Test2.pdf");

            using (
                var message =
                await client.PostAsync("https://api.na2.echosign.com/api/rest/v6/transientDocuments", content))
            {
                var input = await message.Content.ReadAsStringAsync();
                Console.WriteLine(input);
            }
        }
    }

在此处输入图像描述

4

0 回答 0