I'm attempting to pull the variable GetHttpRequestData().headers.accept-language
in ColdFusion 2018, but am getting an error.
The main object
GetHttpRequestData().headers
looks fine. This is information from the html request header.I can also pull back other values in the headers object like
GetHttpRequestData().headers.host
orGetHttpRequestData().headers.accept
However, if the variable name contains a dash ie.
GetHttpRequestData().headers.accept-language
, I get an error because CF Thinks I'm executing a mathematical function.
How can I return this variable? It should be simple.
// Dump the Object
writeDump(var="#GetHttpRequestData().headers#",format="html")
// Dump a result in the Object OK
writeDump(var="#GetHttpRequestData().headers.host#",format="text")
// Dump a result in the Object OK
writeDump(var="#GetHttpRequestData().headers.accept#",format="text")
// CF Thinks I'm executing a mathematical function
// when structure variable has a dash in the name
try {
writeDump(var="#GetHttpRequestData().headers.accept-language#",format="text")
} catch (any e) {
writeOutput("Error: " & e.message);
}