我正在尝试测试 REST API 以在 WCF Web 服务中使用 C# 通过模板引用的文档请求签名。
登录的第 1 步有效并返回 accountID 和 baseURl;
步骤 2 失败并显示Bad Request
.
这是我的代码:
try {
...
string requestBody = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
"<accountId>" + accountId + "</accountId>" +
"<status>" + "sent" + "</status>" +
"<emailSubject>" + "API Call for Embedded Sending" + "</emailSubject>" +
"<emailBlurb>" + "This comes from C#" + "</emailBlurb>" +
"<templateId>" + "9A535489-0FB6-42B2-82C1-A06DA36025B4" + "</templateId>" +
"<templateRoles>" +
"<email>" + "abc@gmail.com" + "</email>" + // NOTE: Use different email address if username provided in non-email format!
"<name>" + "GRAVITY1003" + "</name>" + // username can be in email format or an actual ID string
"<roleName>" + "GRAVITY1003" + "</roleName>" +
"</templateRoles>" +
"</envelopeDefinition>";
// append "/envelopes" to baseUrl and use in the request
request = (HttpWebRequest)WebRequest.Create(baseURL + "/envelopes");
request.Headers.Add("X-DocuSign-Authentication", authenticateStr);
request.ContentType = "application/xml";
request.Accept = "application/xml";
request.ContentLength = requestBody.Length;
request.Method = "POST";
// write the body of the request
byte[] body = System.Text.Encoding.UTF8.GetBytes(requestBody);
Stream dataStream = request.GetRequestStream();
dataStream.Write(body, 0, requestBody.Length);
dataStream.Close();
// read the response
webResponse = (HttpWebResponse)request.GetResponse();------> It fails here
sr = new StreamReader(webResponse.GetResponseStream());
responseText = sr.ReadToEnd();
uri = responseText;
}
catch (WebException e)
{
using (WebResponse response = e.Response)
{
HttpWebResponse httpResponse = (HttpWebResponse)response;
Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
using (Stream data = response.GetResponseStream())
{
string text = new StreamReader(data).ReadToEnd();
Console.WriteLine(text);
}
}
}
谁能告诉我我做错了什么?我查看了 API 演练并进行了相应的编码。不知道为什么会这样。