Coldfusion - Grabbing the Cookie Value from the ResponseHeader?

Hi Folks,

I'm hitting a brick wall with this one.

I'm using CFHTTP to attempt a login (and later, a file download) on a remote server.  I've managed to accomplish this by passing a static cookie value within the cfhttpparam, though obviously in reality I'm going to need to get this 'on the fly' (the cookie is a session variable, I logged in manually to find it, then ran my cfhttp immediately after before the session expired).

So far, I've got so far as to getting in and retrieving the cfhttp responseheader.  A cfdump shows me the value is there, I simply can't figure out how to grab it so I can pass it onto the next cfhttp request.

Existing code shown below (I've also attached a screenshot of the cfdump so you can see the responseheader as I'm seeing it;
<!--- Simple cfhttp to grab the headers --->
<cfhttp url="https://www.remotedomain.com/Default.aspx" method="post" result="getCookie">
<cfhttpparam type="header" name="txtUsername" value="myuser">
<cfhttpparam type="header" name="txtPassword" value="mypass">
</cfhttp>

<cfdump var="#getCookie#">

<cfset thisCookie = ListGetAt(getCookie.responseHeader["Set-Cookie"],1,"=")>
<!--- The Above shows me only the Cookie Name (in this instance ASP.NET_SessionId) --->

Open in new window

Screen-shot-2010-04-22-at-21.47..png
ReveroomAsked:
Who is Participating?
 
_agx_Commented:
Correction:

<cfset thisCookie = ListGetAt(getCookie.responseHeader["Set-Cookie"], 2,"=")>
<cfset thisCookie = ListGetAt(thisCookie, 1,";")>
0
 
_agx_Commented:
It you wanted the value, you'd need to grab the second position

 <cfset thisCookie = ListGetAt(getCookie.responseHeader["Set-Cookie"], 2,"=")>

But I'm not sure this is the right way to pass the information along.  
0
 
ReveroomAuthor Commented:
Excellent, thanks agx - much appreciated.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.