<cfhttp>以在ColdFusion中下载远程.csv文件

时间:2018-09-25 21:11:25

标签: coldfusion cfml cfhttp coldfusion-2016 cfhttpparam

我正在尝试使用ColdFusion(2016版)在远程服务器位置下载.csv文件。我使用cfhttp标记执行此操作,但始终收到以下错误:

401 UNAUTHORIZED

我与远程服务器的服务器管理员进行了核对,以验证我是否具有正确的域名,用户名和密码,并由管理员进行了确认。我在SO上找不到任何类似的内容,因此发布了这个问题。希望有人可以帮助我。

PS:我无法访问ColdFusion Administrator,因为它是由一个单独的团队托管。

以下是我的代码(为安全起见,实际值已替换为伪数据):

  <cfhttp  url="https://xxx.yyy.com/abcd/xyz/myfolder/myFile.csv">
    <cfhttpparam type="header" name="Authorization"  
        value="Basic #ToBase64("MydomainName\Myuserid:Mypassword")#" />
  </cfhttp>
  <cfdump  var="#cfhttp.filecontent#" label="CSV file content">
  <cfabort>

1 个答案:

答案 0 :(得分:2)

可能是您的身份验证字符串错误。为避免混乱和调试时,我建议使用以下内容:


<cfset myDomainName = "MydomainName" />
<cfset myUserId = "Myuserid" />
<cfset myPassword = "Mypassword" />

<cfset authString = "Basic " & ToBase64('#myDomainName#' & '\' & '#myUserId#' & ':' & '#myPassword#') />

<cfhttp  url="https://xxx.yyy.com/abcd/xyz/myfolder/myFile.csv">

  <cfhttpparam type="header" name="Authorization"  
        value="#authString#" />

</cfhttp>

<cfdump  var="#cfhttp.filecontent#" label="CSV file content">
<cfabort>

我希望这会有所帮助。