我正在努力弄清楚如何读取 cfhttp.responseHeader
的内容。我正在尝试访问一个在响应中发送几个 cookie 的网站。我需要从响应中提取它们。然后将 cookie 值与所有 future 请求一起发送。我尝试使用以下代码:
<cfloop collection = #cfhttp.responseHeader# item = "httpHeader">
<cfset value = cfhttp.responseHeader[httpHeader]>
<cfif IsSimpleValue(value)>
<cfoutput>
#httpHeader# : #value#<BR>
</cfoutput>
<cfelse>
<cfloop index = "counter" from = 1 to = #ArrayLen(value)#>
<cfoutput>
#httpHeader# : #value[counter]#<BR>
</cfoutput>
</cfloop>
</cfif>
但是会抛出如下错误
Object of type class coldfusion.util.FastHashtable cannot be used as an array
The error occurred in C:/inetpub/wwwroot/cfdocs/Response.cfm: line 22
20 : </cfoutput>
21 : <cfelse>
22 : <cfloop index = "counter" from = 1 to = #ArrayLen(value)#>
23 : <cfoutput>
24 : #httpHeader# : #value[counter]#<BR>
最佳答案
您可以像这样检索 cookie:
<cfset cookies = cfhttp.responseHeader["set-cookie"] />
<cfdump var="#cookies#" />
然后您可以使用该 cookie 结构数据来发出后续请求。
关于Coldfusion CFHTTP.Responseheader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11834128/