coldfusioncfhttp

connecting to smarter stats through cfhttp


I am trying to get connected to smarter stats website by by passing the login window and load the statistics in a fancybox page

so far this is my code: but that does not seems to be working

<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>

problem is every time i load the page

http://domain.in/index.cfm it comes back to http://domain.in/stats/Login.aspx

I am using hostek website's stats provide for a domain


Solution

  • The reason your code is behaving this way is because the initial URL you have in your cfhttp tag is returning an HTTP 302 redirect. Then because you have the redirect attribute of the cfhttp tag set to true it is actually performing the redirect. Look at the documentation for that attribute:

    redirect - If the response header includes a Location field AND ColdFusion receives a 300-series (redirection) status code, specifies whether to redirect execution to the URL specified in the field:

    • yes: redirects execution to the specified page.
    • no: stops execution and returns the response information in the cfhttp variable, or throws an error if the throwOnError attribute is True.
      The cfhttp.responseHeader.Location variable contains the redirection path. ColdFusion follows a maximum of four redirects on a request. If there are more, ColdFusion functions as if redirect = "no".
      Note: The cflocation tag generates an HTTP 302 response with the url attribute as the Location header value.

    So instead of using that initial URL for your cfhttp request, try using the URL it is redirecting to. And set the redirect attribute to false. But be aware that having that attribute set to false the tag will throw an error if it gets a redirect status code so you will need to handle that.

    Example:

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