我在Java中使用REST API用于DocuSign。我尝试使用文档嵌入签名(最终进入我的页面中的iframe),而不是像API演练中那样嵌入模板。通过这里看,我读到这可以通过合并来自embeddedSigning和requestSigning API演练的代码来完成,但我很难做到这一点。现在我觉得我已经接近了,但却发现了一个我不知道它在说什么的错误。
//============================================================================
//STEP 2 - Signature Request on Document API Call
//============================================================================
url = baseURL + "/envelopes"; // append "/envelopes" to baseUrl for signature request call
//this example uses XML formatted requests, JSON format is also accepted
//following body will place one signature tab 100 pixels right and 100 down from top left corner of document
body = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
"<status>sent</status>" +
"<emailSubject>API Call for adding signature request to document and sending</emailSubject>" +
//add document(s)
"<documents>" +
"<document>" +
"<documentId>1</documentId>" +
"<name>" + documentName + "</name>" +
"</document>" +
"</documents>" +
//add recipient(s)
"<recipients>" +
"<signers>" +
"<signer>" +
"<recipientId>1</recipientId>" +
"<name>" + recipientName + "</name>" +
"<email>" + recipientEmail + "</email>" +
"<clientUserId>1001</clientUserId>" +
"<tabs>" +
"<signHereTabs>" +
"<signHere>" +
"<xPosition>100</xPosition>" +
"<yPosition>100</yPosition>" +
"<documentId>1</documentId>" +
"<pageNumber>1</pageNumber>" +
"</signHere>" +
"</signHereTabs>" +
"</tabs>" +
"</signer>" +
"</signers>" +
"</recipients>" +
"</envelopeDefinition>";
// re-use connection object for second request...
conn = InitializeRequest(url, "POST", body, authenticationHeader);
// read document content into byte array
File file = new File("./" + documentName);
InputStream inputStream = new FileInputStream(file);
byte[] bytes = new byte[(int) file.length()];
inputStream.read(bytes);
inputStream.close();
// start constructing the multipart/form-data request...
String requestBody = "\r\n\r\n--BOUNDARY\r\n" +
"Content-Type: application/xml\r\n" +
"Content-Disposition: form-data\r\n" +
"\r\n" +
body + "\r\n\r\n--BOUNDARY\r\n" + // our xml formatted request body
"Content-Type: " + docContentType + "\r\n" +
"Content-Disposition: file; filename=\"" + documentName + "\"; documentid=1\r\n" +
"\r\n";
// we break this up into two string since the PDF doc bytes go here and are not in string format.
// see further below where we write to the outputstream...
String reqBody2 = "\r\n" + "--BOUNDARY--\r\n\r\n";
// write the body of the request...
DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );
dos.writeBytes(requestBody.toString());
dos.write(bytes);
dos.writeBytes(reqBody2.toString());
dos.flush(); dos.close();
System.out.println("STEP 2: Creating envelope from document...\n");
status = conn.getResponseCode(); // triggers the request
if( status != 201 ) // 201 = Created
{
errorParse(conn, status);
return;
}
// obtain envelope uri from response body
response = getResponseBody(conn);
String uri = parseXMLBody(response, "uri");
System.out.println("-- Envelope Creation response --\n\n" + prettyFormat(response, 2));
//============================================================================
//STEP 3 - Get the Embedded Signing View
//============================================================================
url = baseURL + uri + "/views/recipient"; // append envelope uri + "views/recipient" to url
//this example uses XML formatted requests, JSON format is also accepted
body = "<recipientViewRequest xmlns=\"http://www.docusign.com/restapi\">" +
"<authenticationMethod>email</authenticationMethod>" +
"<email>" + recipientEmail + "</email>" +
"<returnUrl>http://www.docusign.com/devcenter</returnUrl>" +
"<clientUserId>1001</clientUserId>" + //*** must match clientUserId set in Step 2!
"<userName>" + recipientName + "</userName>" +
"</recipientViewRequest>";
System.out.print("Step 3: Generating URL token for embedded signing... ");
conn = InitializeRequest(url, "POST", body, authenticationHeader);
status = conn.getResponseCode(); // triggers the request
if( status != 201 ) // 201 = Created
{
errorParse(conn, status);
return;
}
System.out.println("done.");
response = getResponseBody(conn);
String urlToken = parseXMLBody(response, "url");
System.out.println("\nEmbedded signing token created:\n\t" + urlToken);
我收到了这个错误:
步骤3:为嵌入式签名生成URL令牌... API调用失败,返回的状态为:411 [致命错误]:1:50:publicId和systemId之间需要空格。
我对这一切都很陌生,所以任何有关我应该如何嵌入文件签名的帮助都将非常感激。 错误:&#39; publicId和systemId之间需要空格。&#39;
答案 0 :(得分:1)
根据RFC 2616标准,HTTP错误411
表示缺少Content-Length
标头。尝试将Content-Length
标头添加到请求中,并将其设置为您正在构建的请求正文的大小。