0

我正在尝试使用 ColdFusion 做一个简单的签名请求。我的代码基于提供的示例,但不断收到同样的错误。我尝试使用经过验证的 XML 和 JSON 并得到相同的错误。这是我的代码:

<cfset envDef = "<envelopeDefinition xmlns=\'http://www.docusign.com/restapi\'>" & 
"<emailBlurb>This is a test</emailBlurb>" & 
"<emailSubject>API Call for adding signature request to document and sending</emailSubject>" & 
"<status>sent</status>" & 
"<documents>" &
"<document>" & 
"<documentId>1</documentId>" & 
"<name>test.txt</name>" & 
"</document>" & 
"</documents>" &
"<recipients>" & 
"<signers>" & 
"<signer>" & 
"<recipientId>1</recipientId>" & 
"<email>cjfennim@earthlink.net</email>" &   
"<name>Charles Fennimore</name>" & 
"<tabs>" & 
"<signHereTabs>" & 
"<signHere>" & 
"<xPosition>100</xPosition>" & 
"<yPosition>100</yPosition>" & 
"<documentId>1</documentId>" & 
"<pageNumber>4</pageNumber>" & 
"</signHere>" &
"</signHereTabs>" & 
"</tabs>" & 
"</signer>" & 
"</signers>" & 
"</recipients>" &  
"</envelopeDefinition>">

<cfset filePath = ExpandPath("../test.txt") />

<!--- read contents of document into the request stream --->
<cffile action="read" file="#filePath#" variable="fileStream" charset="utf-8">

<!--- build the multipart request body --->
<cfset requestBodyStart = "\r\n\r\n--BOUNDARY\r\n" &
            "Content-Type: application/xml\r\n" &
            "Content-Disposition: form-data\r\n" &
            "\r\n" &
            envDef & "\r\n\r\n--BOUNDARY\r\n" & 
            "Content-Type: text/plain\r\n" &
            "Content-Disposition: file; filename='test.txt'; documentId=1; fileExtension='txt'\r\n" &
            "\r\n">

<cfset requestBodyEnd = "\r\n--BOUNDARY--\r\n\r\n">

<cfset requestBody = requestBodyStart & fileStream & requestBodyEnd>

<cfset requestBodyLength = LEN(requestBody)>

<cfhttp url="#theurl#" method="post" multipart="yes">
<cfhttpparam type="header" name="X-DocuSign-Authentication" value="#dsAuthHeader#">
<cfhttpparam type="header" name="Accept" value="application/xml">
<cfhttpparam type="header" name="Content-Type" value="multipart/form-data; boundary=BOUNDARY">
<cfhttpparam type="header" name="Content-Length" value="#requestBodyLength#">
<cfhttpparam type="body" value="#requestBody#">
</cfhttp>

这会产生以下 requestBody:

\r\n\r\n--BOUNDARY\r\nContent-Type: application/xml\r\nContent-Disposition: form-data\r\n\r\n<envelopeDefinition xmlns=\'http://www.docusign.com/restapi\'><emailBlurb>This comes from Blue</emailBlurb><emailSubject>API Call for adding signature request to document and sending</emailSubject><status>sent</status><documents><document><documentId>1</documentId><name>test.txt</name></document></documents><recipients><signers><signer><recipientId>1</recipientId><email>cjfennim@earthlink.net</email><name>Charles Fennimore</name><tabs><signHereTabs><signHere><xPosition>100</xPosition><yPosition>100</yPosition><documentId>1</documentId><pageNumber>4</pageNumber></signHere></signHereTabs></tabs></signer></signers></recipients></envelopeDefinition>\r\n\r\n--BOUNDARY\r\nContent-Type: text/plain\r\nContent-Disposition: file; filename='test.txt'; documentId=1; fileExtension='txt'\r\n\r\nTest file\r\n--BOUNDARY--\r\n\r\n

文件 test.txt 包含“测试文件”。

我能够使用相同的标题信息获取信封信息,所以我知道这不是问题。任何帮助,将不胜感激。

使用 cfsavecontent 创建 requestBody 也不起作用:

<cfsavecontent variable="requestBody">

--BOUNDARY
Content-Type: application/xml
Content-Disposition: form-data
#envDef#

--BOUNDARY
Content-Type: text/plain
Content-Disposition: file; filename='test.txt'; documentId=1
#fileStream#

--BOUNDARY--

</cfsavecontent>

并且以 iso-8859-1 而不是 utf-8 编码也不起作用。

4

1 回答 1

0

这可能与 XML 命名空间值周围的单引号字符有关。当我将您的 XML 定义复制到 PHP 中并在那里运行时(我没有 ColdFusion),它抱怨 xml 格式不正确。我不得不将单引号更改为双引号。不确定这是否特定于 PHP,但可能值得一试。

所以基本上,如果你从

<cfset envDef = "<envelopeDefinition xmlns=\'http://www.docusign.com/restapi\'>" &

到这个?

<cfset envDef = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" &
于 2013-07-10T18:51:29.883 回答