Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coldfusion CFHTTP.Responseheader

I am going nuts trying to figure out how to read the content of the cfhttp.responseHeader. I am trying to access a website which sends a couple of cookies in the response. I need to extract them from the response. Then send the cookie values with all future requests. I tried to use below code:

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

But that throws the following error

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> 
like image 260
Alex Ponnath Avatar asked Apr 18 '26 00:04

Alex Ponnath


1 Answers

You can retrieve the cookies like this:

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

<cfdump var="#cookies#" />

You can then use that cookie struct data to make your subsequent requests.

like image 154
Jason Dean Avatar answered Apr 21 '26 11:04

Jason Dean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!