Skip to main content
Ben Nadel at the jQuery Conference 2009 (Cambridge, MA) with: Cody Lindley
Ben Nadel at the jQuery Conference 2009 (Cambridge, MA) with: Cody Lindley ( @codylindley )

CFHttp Error: Column Names Must Be Valid Variable Names In ColdFusion

By
Published in

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 the cfhttp variable which is implicitly defined after the cfhttp tag execution. If you're using the script-based Http() component, this is akin to calling new 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

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel