[英]ColdFusion error retrieving accept-language from GetHttpRequestData().headers
I'm attempting to pull the variable GetHttpRequestData().headers.accept-language
in ColdFusion 2018, but am getting an error. 我正在尝试在ColdFusion 2018中提取变量
GetHttpRequestData().headers.accept-language
,但遇到错误。
The main object GetHttpRequestData().headers
looks fine. 主要对象
GetHttpRequestData().headers
看起来不错。 This is information from the html request header. 这是来自html请求标头的信息。
I can also pull back other values in the headers object like GetHttpRequestData().headers.host
or GetHttpRequestData().headers.accept
我还可以拉回标头对象中的其他值,例如
GetHttpRequestData().headers.host
或GetHttpRequestData().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. GetHttpRequestData().headers.accept-language
,我得到一个错误,因为CF认为我正在执行数学函数。
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);
}
Answer to ColdFusion variables with dash separators. 用破折号分隔符回答ColdFusion变量。
Use the chained variable in the following manner: 通过以下方式使用链接的变量:
#GetHttpRequestData().headers['accept-language']#
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.