简体   繁体   English

从GetHttpRequestData()。headers检索接受语言的ColdFusion错误

[英]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 ,但遇到错误。

  1. The main object GetHttpRequestData().headers looks fine. 主要对象GetHttpRequestData().headers看起来不错。 This is information from the html request header. 这是来自html请求标头的信息。

  2. I can also pull back other values in the headers object like GetHttpRequestData().headers.host or GetHttpRequestData().headers.accept 我还可以拉回标头对象中的其他值,例如GetHttpRequestData().headers.hostGetHttpRequestData().headers.accept

  3. 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. 应该很简单。

cffiddle example 例子

// 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']#
  • note the drop of the point separator 注意点分隔符的掉落

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM