我正在尝试调用Docusign REST API,如'"步骤3:代表用户2发送签名请求"这部分link。我在下面收到以下错误。设定的边界是什么?我该如何正确设置它?
{ " errorCode":" INVALID_MULTI_PART_REQUEST", " message":"解析多部分请求时发现错误。边界终止符' - 边界;字符集= UTF-8 - '在请求中找不到。" }
public static string HttpRequest(string url, List<CELPHttpHeader> headerList, EnvelopeDefinition envelopeDefination)
{
string responseString = string.Empty;
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("accept", "application/json");
MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("multipart/form-data");
NameValueHeaderValue item = new NameValueHeaderValue("boundary", "BOUNDARY");
mediaType.Parameters.Add(item);
JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter();
HttpRequestMessage requestMessage = new HttpRequestMessage();
requestMessage.Method = HttpMethod.Post;
requestMessage.Content = new ObjectContent<EnvelopeDefinition>(envelopeDefination, formatter, mediaType);
foreach (CELPHttpHeader header in headerList)
{
client.DefaultRequestHeaders.Add(header.Name, header.Value);
}
try
{
Task<HttpResponseMessage> webTaskResult = client.PostAsync(url, requestMessage.Content);
webTaskResult.Wait();
HttpResponseMessage response = webTaskResult.Result;
}
catch (Exception ex)
{
}
return (responseString);
}
答案 0 :(得分:3)
API请求应如下所示:“
--BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
<JSON request here>
}
--BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="test1.pdf"; documentid=1
Content-Transfer-Encoding: base64
JVBERi0xLjUNJeLjz9MNCjMwMDIgMCBvYmoNPDwvTGluZWFyaXplZCAxL0wgMTM1
<snipped>
V1sxIDMgMF0+PnN0cmVhbQ0KaN5iYhRZU8PEwCDsBCQY1wMJpicAAQYAHeIDMQ0K
ZW5kc3RyZWFtDWVuZG9iag1zdGFydHhyZWYNCjEzNjA0NjUNCiUlRU9GDQo=
--BOUNDARY--