views:

1078

answers:

5

I am using ColdFusion 8.

I'm doing a CFHTTP Post to a remote server. The remote site has looked at their logs and they say my code is doing the POST, and then immediately doing a 2nd GET request.

Here is my code (the URL has been changed):

<cfhttp url="https://www.theurlofthesite.com" method="POST" port="443" resolveurl="yes" redirect="yes">
<cfhttpparam type="FORMFIELD" name="type" value="SALES">
<cfhttpparam type="FORMFIELD" name="account" value="10003">
<cfhttpparam type="FORMFIELD" name="Submit" value="Submit+Request">
</cfhttp>

<Cfoutput>#cfhttp.fileContent#</CFOUTPUT>

<cfdump var="#cfhttp#">

Does anyone have any idea why they are seeing a 2nd GET request right after my POST? it's trashing the session and not returing the page correctly because of this (we think)

I'm definately not doing a GET, I'm only doing the one POST.

thanks,

Rich

A: 
redirect="false" //maybe?

Not sure... Since the doc said...

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.

Henry
I tried redirect="no" but got the same results
Rich
A: 

Is this code inside a custom CF tag? If so then calling

<mytag>...</mytag>

or

<mytag />

Calls the custom tag TWICE! (Once for the start tag and once for the end.)

Chris Nava
This wouldn't explain why the second hit is a GET
Antony
While I don't think this explains the original problem, you should include how to prevent this behavior (when desired): <cfif thisTag.executionMode = "end"><cfexit method="exitTag"/></cfif> and anyone interested in why it works this way should read this page from the livedocs: http://livedocs.adobe.com/coldfusion/8/htmldocs/reuseCode_7.html
Adam Tuttle
+4  A: 

I'm guessing the reason you get the second GET is that your CFOUTPUT outputs the retrieved page content into the browser, then when an image or something from that content is rendered from the retrieved page it acts as a GET.

Remember that CFHTTP is not stateful. By this I mean that each request with CFHTTP will create a new session. You can get CFHTTP to continue with an existing session by passing in CFID/CFTOKEN through with CFHTTPPARAM in the request. This might explain your session issues.

Dave Quested
You could test this.. remove the cfdump tag, and change the cfouput to this: <cfoutput><pre>#HTMLEditFormat(cfhttp.fileContent)#</pre></cfoutput>. That will show you exactly what you're getting, and make sure the browser isn't making any follow-up requests.
Kip
A: 

ok, I switched over to a CF 5 server, and it stopped doing the 2nd GET. it's just doing a POST now, so it might be a quirk with CF 8.

Rich
If so that definitely seems like a bug to me...
Kip
A: 

If you are using firefox, make sure you have firebug and ySlow turned off for your request. They fire your urls twice to set up their data and can be a real problem when you don't know that they are doing that.

Also, try turning the redirect off unless you need it.

anopres
thanks. turns out after I switched back to CF5 (from CF8) the 2nd GET stopped. weird
Rich