2016-03-31 16 views
0

我試圖調用Docusign REST API,如在link中的「步驟3:發送代表用戶2的簽名請求」部分所述。我在下面得到以下錯誤。假定的邊界是什麼?我如何正確設置它?Docusign REST API調用 - 「沒有找到邊界終結符」

{ 「的errorCode」: 「INVALID_MULTI_PART_REQUEST」, 「消息」:「在解析multipart請求信息中發現錯誤邊界終止 '--boundary;字符集= 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

見路易斯的答案 - 我想你請求中的邊界越來越錯誤編碼。 「; charset = utf-8」看起來像來自另一個參數。應該使用行分隔符而不是分號將邊界與零件標題分開。 –

+0

謝謝傑夫,我認爲問題是EnvelopeDefination格式錯誤,並且多部分請求的格式也是錯誤的。 –

回答

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