我正在尝试使用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包含&#34;测试文件&#34;。
我能够使用相同的标题信息获取信封信息,所以我知道这不是问题。任何帮助将不胜感激。
使用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中编码也不起作用。
答案 0 :(得分: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\">" &