3 Replies Latest reply on Mar 29, 2007 8:57 AM by Newsgroup_User

    CFHTTP not functioning properly

    davidsimms Level 1
      The following is in application.cfc:

      <cffunction name="onRequestStart">
      <CFIF (RIGHT(CGI.SCRIPT_NAME, 9) NEQ "login.cfm") AND (NOT isDefined("SESSION.loggedIn"))>
      <CFLOCATION URL="login.cfm?notLoggedIn=yes" addtoken="no">
      </CFIF>
      </cffunction>

      A template named index.cfm exists alongside this application.cfc and contains the following code:

      <cfhttp method="post" url=' http://localhost/test/testPost.cfm'>
      <cfhttpparam name="testValue" value="My test value." type="formfield">
      </cfhttp>

      This CFHTTP fails to function (code in testPost.cfm should simply append a line to a log file) when the conditional statement above is in the onRequestStart method. If I remove that conditional statement from the onRequestStart method, the CFHTTP tag functions perfectly.

      Why would that CFIF statement in the onRequestStart method interfere with the CFHTTP block in index.cfm?

      David

        • 1. Re: CFHTTP not functioning properly
          Level 7
          Why would that CFIF statement in the onRequestStart method interfere
          with the CFHTTP block in index.cfm?


          Because it is doing exactly what you are telling it to do.


          The if statement says if the page is not index.cfm and session.loggedIn
          is not defined, then go to login.cfm.

          Then you run a cfhttp tag which makes a request to a page named
          testPost.cfm which is NOT index.cfm. And since the CF client used to
          make that http request has not been LOGGED in and does not have a
          session.loggedIn value, the request is redirected to login.cfm. A bit
          of an endless loop there.

          Remember when one uses <CFHTTP...> it is creating normal http request
          just like any other client using a very basic built in 'browser'. It is
          subject to any and all restrictions applied to requests.

          • 2. Re: CFHTTP not functioning properly
            davidsimms Level 1
            You're right Ian. I neglected to regard CF as a separate client from my browser--which IS logged in. The CF "browser" of course does not inherit that logged in state. Thanks for the quick reply.
            • 3. Re: CFHTTP not functioning properly
              Level 7
              I neglected to regard CF as a separate client from my browser--which IS
              logged in. The CF "browser" of course does not inherit that logged in state.


              A very common problem, and one of the first things to look at when
              debugging <cfhttp...>, <cfftp...>, <cfexecute...>, schedule tasks and
              network UNC paths used in <cffile...> and <cfdirectory...> tags. All
              these use the permissions of the CF service which usually is very
              different then the developer's.