1

我正在尝试发送包含 Base64 编码的二进制文件的 xml。当我调用时cfhttp,我的 ColdFusion 10 服务器一直挂起,直到超时。Visual Studio 即时调试器不断弹出。

我正在使用这篇文章中 Ben Nadel 的教程。有人可以帮忙吗?

  <cffunction name="_push" access="public" returntype="Any">
<!---
  Create the path to the binary file that we want to
  post via a web service.
--->
<cfset strFilePath = ExpandPath( './myfile.zip' ) />



<!--- Read in the binary file. --->
<cffile
  action="readbinary"
  file="#strFilePath#"
  variable="objBinaryData"
  />


<!---
  Create the XML that we are going to post. When posting this
  file, we are going to encode it as base64 text data.
--->
<!--- <cfsavecontent variable="strXmlData"> --->
<cfxml variable="strXmlData">
  <cfoutput>

    <file>
      <name>#XmlFormat(
        ListLast( strFilePath, "\/" )
        )#</name>

      <ext>#XmlFormat(
        ListLast( strFilePath, "." )
        )#</ext>

      <!---
        When storing the binary data, we are going to
        pass the file as a Base64 encoding. I am like
        95% sure that this will result in only valid
        XML characters, but I am not completely sure.
      --->
      <base64>#BinaryEncode(objBinaryData,"Base64")#</base64>
    </file>
  </cfoutput>
</cfxml>
<!--- </cfsavecontent> --->


<!---
  Build the URL for the "web service" to which we are going
  to post this file data.
--->
<cfset strUrl = (
  GetDirectoryFromPath(
    GetPageContext().GetRequest().GetRequestUrl().ToString()
    ) &
  "webservice.cfm"
  ) />


<cftry>

  <!--- Post the XML data to the "web service" file. --->
  <cfhttp
    url="#strUrl#"
    result="httpresponse"
    method="post"
    throwOnError="yes"
    timeout="60">

    <!--- Post XML data. --->
    <cfhttpparam
      type="xml"
      value="#strXmlData#"
      name="myxml"
      />

  </cfhttp>               

   <cfcatch type="any">
      <cfdump var="#cfcatch#" output="c:/dump-a.txt">
      <cfset httpresponse = cfcatch>
   </cfcatch>
</cftry> 


 <cfreturn httpresponse>

这是 webservice.cfm 文件内容

  <!--- Grab the content from the request data post. --->
  <cfset strContent = Trim( GetHttpRequestData().Content ) />
  <cfdump var="#strContent#" output="c:/webs/dump-b.txt">


  <!--- Check to see if the content is a valid XML document. --->
  <cfif IsXml( strContent )>
     <!---
        Parse the XML data into a ColdFusion Xml
        Document Object.
     --->
     <cfset xmlPost = XmlParse( strContent ) />

     <!---
        Check to see if we have all the XML nodes that we
        need in order to save the file. For our naming
        purposes, all we need is the file extension and
        the base64 data.
     --->
     <cfif (
        StructKeyExists( xmlPost.file, "ext" ) AND
        StructKeyExists( xmlPost.file, "base64" )
        )>

        <!---
           ASSERT: We have the nodes that we need, and for
           this demo, we are just going to assume that the
           data values are valid.
        --->

        <!---
           Create the file name for the target file. We are
           going to use the passed in extension and a UUID.
           Make sure that file name points to the executing
           script directory (ExpandPath()).
        --->
        <!---
        <cfset strFileName = ExpandPath(
           CreateUUID() & "." &
           xmlPost.file.ext.XmlText
           ) />
           --->
        <cfset ExpandPath( CreateUUID()&'.'& xmlPost.file.ext.XmlText) />

        <!---
           Grab the base64 file data and convert it to
           binary data.
        --->
        <cfset objBinaryData = ToBinary(
           xmlPost.file.base64.XmlText
           ) />


        <!--- Write the binary file data to disk. --->
        <cffile
           action="write"
           file="#strFileName#"
           output="#objBinaryData#"
           />           

     </cfif>

  </cfif>     

我正在我的开发机器上测试这个,它运行在 Windows 8 和 ColdFusion 10(开发者版)上。

4

0 回答 0