CFHttp Error: Column Names Must Be Valid Variable Names In ColdFusion
One of the peculiarities of the ColdFusion language is that some operations are capable of returning two different kinds of data (results and metadata). And, some operations are capable of returning the same result using two different mechanisms. Most of the time, this is fine—you develop the patterns of consumption that work best for your particular style of coding. But, sometimes your brain farts and you end up with strange error messages.
This is what happened to me yesterday when invoking the CFHttp
tag in ColdFusion. I was making a simple GET
request:
<cfscript>
cfhttp(
name = "httpResponse",
method = "get",
url = "https://www.bennadel.com/",
timeout = 3
);
</cfscript>
... and ended up with this runtime error:
Column names must be valid variable names. They must start with a letter and can only include letters, numbers, and underscores.
coldfusion. runtime. QueryFunction$ QueryColumnNameException: The column name
<!doctype html>
is invalid.
The CFHttp
tag is a strange tag. And it has some strange (in my opinion) legacy behaviors; one of which is parsing the returned fileContent
into a ColdFusion Query object. Instead of indicating this behavior through some processing attribute, like returnAsQuery
, ColdFusion differentiates this pathway through the existence of the name
attribute.
If you look at my ColdFusion code above, you'll see that I'm using name="httpResponse"
. This is telling ColdFusion to parse the HTTP fileContent
into a query object called httpResponse
. Hence the above error.
What I intended to do was use the result
attribute:
<cfscript>
cfhttp(
result = "httpResponse",
method = "get",
url = "https://www.bennadel.com/",
timeout = 3
);
</cfscript>
This works fine; and, tells ColdFusion to save the HTTP fileContent
into a variable named httpResponse
.
Aside: Without the
result
attribute, the HTTP response can also be accessed using thecfhttp
variable which is implicitly defined after thecfhttp
tag execution. If you're using the script-basedHttp()
component, this is akin to callingnew Http().send().getPrefix()
.
Want to use code from this post? Check out the license.
Reader Comments
Post A Comment — ❤️ I'd Love To Hear From You! ❤️
Post a Comment →