• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFHTTP not functioning properly

Contributor ,
Mar 29, 2007 Mar 29, 2007

Copy link to clipboard

Copied

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

TOPICS
Advanced techniques

Views

416

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 29, 2007 Mar 29, 2007
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 ...

Votes

Translate

Translate
LEGEND ,
Mar 29, 2007 Mar 29, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 29, 2007 Mar 29, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 29, 2007 Mar 29, 2007

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation