Coldfusion CFHTTP.Responseheader

Coldfusion CFHTTP.Responseheader,coldfusion,coldfusion-9,Coldfusion,Coldfusion 9,我想弄清楚如何阅读cfhttp.responseHeader的内容,真是疯了。我正在尝试访问一个网站,该网站在回复中发送了一些cookies。我需要从回复中提取它们。然后将cookie值与所有未来请求一起发送。我尝试使用以下代码: <cfloop collection = #cfhttp.responseHeader# item = "httpHeader"> <cfset value = cfhttp.responseHeader[httpHeader]>

我想弄清楚如何阅读
cfhttp.responseHeader
的内容,真是疯了。我正在尝试访问一个网站,该网站在回复中发送了一些cookies。我需要从回复中提取它们。然后将cookie值与所有未来请求一起发送。我尝试使用以下代码:

<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>

#httpHeader:#值#
#httpHeader:#值[计数器]#

但这会引发以下错误

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> 
类型为coldfusion.util.FastHashtable的对象不能用作数组 错误出现在C:/inetpub/wwwroot/cfdocs/Response.cfm:第22行 20 : 21 : 22 : 23 : 24:#httpHeader#:#值[计数器]#

您可以像这样检索cookie:

<cfset cookies = cfhttp.responseHeader["set-cookie"] />

<cfdump var="#cookies#" />


然后,您可以使用该cookie结构数据进行后续请求

问题是您试图在结构上循环,但将其视为数组。您需要使用“集合”在结构上循环

<cfloop collection="#cfhttp.responseHeader['set-cookie']#" item="sKey">
    .....
</cfloop>

.....

以下是我制作的一个脚本,用于使用Ben Nadel网站上的参考信息获取标题cookie

public struct function GetResponseCookies(required struct Response){
    var LOCAL = {};
    LOCAL.Cookies = {};

    if(!StructKeyExists(ARGUMENTS.Response.ResponseHeader,"Set-Cookie")){
        return LOCAL.Cookies;
    }

    LOCAL.ReturnedCookies = ARGUMENTS.Response.ResponseHeader[ "Set-Cookie" ];

    if(!isStruct(LOCAL.ReturnedCookies)){
        return LOCAL.Cookies;
    }

    for(LOCAL.CookieIndex in LOCAL.ReturnedCookies){
        LOCAL.CookieString = LOCAL.ReturnedCookies[ LOCAL.CookieIndex ];

        for(LOCAL.Index =1; Local.Index != ListLen( LOCAL.CookieString, ';' ); LOCAL.Index++){
            LOCAL.Pair = ListGetAt(LOCAL.CookieString,LOCAL.Index,";");
            LOCAL.Name = ListFirst( LOCAL.Pair, "=" );

            if(ListLen( LOCAL.Pair, "=" ) > 1){
                LOCAL.Value = ListRest( LOCAL.Pair, "=" );
            } else {
                LOCAL.Value = "";
            }

            if(LOCAL.Index EQ 1){
                LOCAL.Cookies[ LOCAL.Name ] = {};
                LOCAL.Cookie = LOCAL.Cookies[ LOCAL.Name ];
                LOCAL.Cookie.Value = LOCAL.Value;
                LOCAL.Cookie.Attributes = {};
            } else {
                LOCAL.Cookie.Attributes[ LOCAL.Name ] = LOCAL.Value;
            }
        }
    }
    return LOCAL.Cookies;   
}