2016-03-31 10 views
0

linkの「ステップ3:ユーザー2に代わって署名要求を送信する」セクションで概説したように、Docusign REST APIを呼び出そうとしています。以下のエラーが表示されます。境界には何が設定されていますか?どのように正しく設定するのですか?Docusign REST APIコール - 「境界ターミネーターが見つかりませんでした」

{ "のerrorCode": "INVALID_MULTI_PART_REQUEST"、 "メッセージ":「マルチパート要求の解析中にエラーが検出された境界ターミネーター '--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); 
} 
+0

参照ルイス答えは - 私はあなたの要求で境界が誤エンコードを得ていると思います。 "; charset = utf-8"は別のパラメータから来ているようです。境界は、セミコロンではなく、行区切り記号を使用してパーツのヘッダーから区切る必要があります。 –

+0

ありがとうございましたJeff、私は問題が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-- 
関連する問題