[thelist] HTTP/1.1 302 Found

.jeff jeff at members.evolt.org
Thu Jan 17 16:42:48 CST 2002


frank,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Frank
>
> > I've got a form, using POST that when submitted,
> > causes an HTTP 302 (Found). It presents me with a
> > link to the same document that I thought I was using.
>
> I posted a form to itself. If certain conditions were
> met, there would be an insert, then a CFLOCATION.
>
> My form used the POST scope. CFLOCATION uses the GET
> scope.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

you're sort of correct about cflocation.  cflocation itself doesn't use any
request method though.  all it really does is sends two headers to the
browser, 302 Object Moved and the new url, and then aborts further
processing of the template.  it's really just shorthand for this:

<cfheader statuscode="302" statustext="Object Moved">
<cfheader name="location" value="#url#">
<cfabort>

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> The server didn't know which to use, so did as it
> should, it presented me with an HTTP 302 Found message.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

actually, you're template ran correctly, without error.  it was your browser
that had a difficulty with the header and puked on it.  were you using nn4?
if so, that's common with nn4.

as you'll see above, the 302 message is actually how cflocation works and
not an indication the server fouled up somehow or was confused.

the fact that your form uses the post request method really only means one
thing -- there's extra data sent with the request beyond just the url.  in a
get request method, all data (sans cookies and other extraneous headers) are
sent in the url.  with a post method, you can still sent data in the url
(using the query string), but you also can send additional data (form field
values).

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> The solution is this: When the form uses POST, use
> CFHTTP to redirect. When the form uses GET, use
> CFLOCATION.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

<cfhttp> does not perform a redirect.  think of <cfhttp> as a web browser
built into coldfusion that can make any request you like, but instead of
automatically outputting the results it simply stores the result (all the
html for the url you requested) in a variable for use within the calling
template.  your browser doesn't actually go anywhere though, as evidenced by
the fact that the url doesn't change, even if you change the url requested
in the <cfhttp> tag to something other than the same template your browser
is requesting.

take this example as a guide.  go take a peek at yahoo.com right now.  then,
take a peek at the following url:

http://members.evolt.org/jeff/yahoo.cfm

notice they're the same (except for my browser "toolbar" that shows up for
ie5+/win users)?

all i have is the following code in yahoo.cfm:

<cfhttp url="http://www.yahoo.com/" method="GET"></cfhttp>

<cfoutput>
#cfhttp.filecontent#
</cfoutput>

[aside:  if you're requesting the same page via <cfhttp>, what's to keep the
cf server from spawning that process over and over again?  ie, you request
the page which runs the <cfhttp> which requests the same page which runs the
<cfhttp> which requests the same page which runs the <cfhttp> which requests
the same page ....]

thanks,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list