文档签名 REST API 调用 - "找不到边界终止符"



我正在尝试调用Docusign REST API,如本链接中"第3步:代表用户2发送签名请求"部分所述。我得到以下错误。边界应该设置为什么?如何正确设置?

{"errorCode":"INVALID_MULTI_PART_REQUEST","message":"分析多部分请求时发现错误。在请求中找不到边界终止符'-Boundary;charset=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);
}

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--

最新更新