通过cfhttp连接到更智能的统计数据

时间:2017-04-09 04:39:43

标签: coldfusion cfhttp

我试图通过传递登录窗口并在fancybox页面中加载统计信息来连接到更智能的统计网站

到目前为止,这是我的代码:但这似乎不起作用

<cfhttp method="post" url="https://stats.ezhostingserver.com/" resolveurl="true" redirect="true">
    <cfhttpparam type="FORMFIELD" name="ctl00$MPH$txtUserName" value="test.ca">
    <cfhttpparam type="FORMFIELD" name="ctl00$MPH$txtPassword" value="mypwd!">
    <cfhttpparam type="FORMFIELD" name="ctl00$MPH$txtSiteId" value="12343">
</cfhttp>
<cfif cfhttp.statuscode EQ '200 OK'>
    <cfhttp result="results" url="https://stats.ezhostingserver.com/default.aspx"/>
    <cfoutput>
        #results.filecontent#
</cfoutput>     
</cfif>

每次加载页面时都会出现问题

http://domain.in/index.cfm 它回来了 http://domain.in/stats/Login.aspx

我正在使用hostek网站的域名提供域名

1 个答案:

答案 0 :(得分:0)

您的代码以这种方式运行的原因是因为cfhttp标记中的初始URL返回HTTP 302重定向。然后,因为您将redirect标记的cfhttp属性设置为true,所以它实际上正在执行重定向。查看该属性的documentation

  

重定向 - 如果响应标头包含“位置”字段并且ColdFusion收到300系列(重定向)状态代码,请指定是否将执行重定向到字段中指定的URL:

     
      
  • 是:将执行重定向到指定的页面。
  •   
  • no:停止执行并返回cfhttp变量中的响应信息,如果throwOnError属性为True则抛出错误。
      cfhttp.responseHeader.Location变量包含重定向路径。 ColdFusion在请求中最多遵循四个重定向。如果还有更多,ColdFusion函数就好像redirect =“no”   注意: cflocation标记生成HTTP 302响应,并将url属性作为Location标头值。
  •   

因此,不要使用cfhttp请求的初始网址,而是尝试使用重定向到的网址。并将redirect属性设置为false。但请注意,如果将该属性设置为false,则标记会在获取重定向状态代码时抛出错误,因此您需要处理该错误。

示例:

<cfhttp method="post" 
        url="https://stats.ezhostingserver.com/Login.aspx" 
        resolveurl="true" 
        redirect="false">
相关问题