我使用cfhttp发布了一些输入到url中,并期望以xls文件的形式下载一些数据。我正在尝试使用cffile ="write“获取数据,但这不起作用。有没有人能建议我们该怎么做。下面是代码
<cfhttp url="#Baseurl#" method="post" result="ExportToExcelresult" redirect="no" resolveurl="true">
<cfhttpparam type="header" name="REFERER" value="#Baseurl#" >
<cfhttpparam type="header" name="Cache-Control" value="no-cache">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
<cfhttpparam type="header" name="Connection" value="keep-alive" >
<cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36">
<cfhttpparam type="header" name="cookie" value="TestCookie=;" encoded="yes">
<cfloop collection="#CookieList#" item="i">
<cfhttpparam type="header" name="cookie" value="#CookieList[i]#" encoded="yes">
</cfloop>
<cfloop collection="#PostCookieList#" item="i">
<cfhttpparam type="header" name="cookie" value="#PostCookieList[i]#" encoded="yes">
</cfloop>
<cfloop collection="#PostDefaultCookieList#" item="i">
<cfhttpparam type="header" name="cookie" value="#PostDefaultCookieList[i]#" encoded="yes">
</cfloop>
<cfhttpparam name="ToolkitScriptManager1_HiddenField" value="" type="formfield">
<cfhttpparam name="LeftNav1_LoginView1_treeView1_ExpandState" value="#EXPANDSTATE#" type="formfield">
<cfhttpparam name="LeftNav1_LoginView1_treeView1_SelectedNode" value="#SELECTNODE#" type="formfield">
<cfhttpparam name="__EVENTTARGET" value="" type="formfield">
<cfhttpparam name="__EVENTARGUMENT" value="" type="formfield">
<cfhttpparam name="LeftNav1_LoginView1_treeView1_PopulateLog" value="" type="formfield">
<cfhttpparam name="__VIEWSTATE" value="#VIEWSTATE#" type="formfield">
<cfhttpparam name="__VIEWSTATEGENERATOR" value="#VIEWSTATEGENERATOR#" type="formfield">
<cfhttpparam name="__EVENTVALIDATION" value="#EVENTVALIDATION#" type="formfield">
<cfhttpparam name="ctl00$MainContent$repMUData$ctl00$btnExport" value="Export to Excel" type="formfield">
</cfhttp>当我执行cfdump时,结果是

当我执行cfdump时,它给出了一些二进制数据。我肯定得到了一些数据,但不确定如何将数据提取到xls文件中
发布于 2019-03-22 03:08:53
要将二进制数据写入文件,只需使用函数filewrite。在下面的代码片段中,我写入了一个临时文件,但如果您想永久存储该文件,则需要写入该文件。然后,我将文件读回到电子表格对象中,以验证写入是否如预期的那样工作。
<cfhttp url="http://example.com/test.cfm" result="ExportToExcelresult">
</cfhttp>
<cfscript>
//Replace with the file path where you want to permanently store the file
yourFileLocation = getTempFile(getTempDirectory() ,"xls");
//Save to file system
filewrite(yourFileLocation, ExportToExcelresult.filecontent.toByteArray());
//Not needed. Only verifying there is a spreadsheet written to the file location
writeOutput("Is spreadsheet: " & isSpreadsheetFile(yourFileLocation));
//You will not be working with a temp file. Do not delete it.
fileDelete(yourFileLocation);
</cfscript>https://stackoverflow.com/questions/55285988
复制相似问题