Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / March 2007



Tip: Looking for answers? Try searching our database.

CFHTTP not functioning properly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
davidsimms - 29 Mar 2007 14:58 GMT
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
Ian Skinner - 29 Mar 2007 15:18 GMT
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.
davidsimms - 29 Mar 2007 15:51 GMT
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.
Ian Skinner - 29 Mar 2007 16:57 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.