Variable CFHTTP is undefined
Hello folks,
I have a script that uses the CFHTTP tag to send in some XML to a url, which returns a code back to my script.
01. <cftry>
02. <cfhttp
03. url="http://the.url.to.post.to"
04. port="443"
05. method="post"
06. resolveurl="yes"
07. throwOnError="Yes"
08. timeout="5"
09. charset="utf-8">
10. <cfhttpparam type="header" name="Accept-Encoding" value="*">
11. <cfhttpparam type="Header" name="TE" value="deflate;q=0">
12. <cfhttpparam type="formField" name="xmlBody" value="#toString(generateRequestXml)#">
13. </cfhttp>
14.
15. <!--- if http request was complete, and "ok" --->
16. <cfif structkeyexists(cfhttp,'statuscode') and listfirst("#cfhttp.statuscode#",' ') eq 200>
17. <!--- hooray, the http request worked fine --->
18. <cfset theVariable = cfhttp.returnedVariable>
19.
20. <!--- else, something went wrong --->
21. <cfelse>
22. <!--- oh no - something went wrong with the request --->
23. <cfthrow />
24. </cfif>
25.
26. <cfcatch type="any">
27. <cfset logError(cfcatch)>
28. </cfcatch>
29. </cftry>
Most of the time, the script works fine, except now and then, it throws an error on line 16 saying that "Variable CFHTTP is undefined". It's as if the cfhttp tag has not finished processing in order to create the "CFHTTP" variable. This sounds a bit like the problem that Charlie Arehart blogged a while back about CF not waiting on some elements - or am I just presuming here?
Anyway - some help would be really useful here, as I'm really scratching my head on this one. I've even tried replicating the error with a CFHTTP url which takes a while to return a response - but no joy.
Help me Adobe Community - you're my only hope....
(heh, I just made that up!! - you can use it)
Cheers,
Phil
