EdomGroup: Inspire, Innovate, Create

Passing cookie values in cfhttp

ColdFusion

If you've ever tried to access a site using cfhttp and that site is expecting a cookie from the browser such as a user id you might be supprised to see cfhttpparam has a type="cookie" attribute. You'll probably be even more supprised when you realize that doesn't work.

The other day I was trying to write a script to access a site that, once logged in, sipmly checked the value of a userid cookie. So, I logged in with firefox and grabbed the value of that cookie and threw is in as

<cfhttpparam type="cookie" name="userid" value="01234">

....and nothing. After a little Google searching I simply loaded up the Live HTTP Headers plugin. This is a great plugin which allows you to see the request in real-time along with all header data (that includes cookies)  going between the browser and server. And there it was my cookie was being passed in as as name="Cookie" value="userid=01234"!! What it turns out is that cookie values get passed in as type="cgi" not type="cookie". What the final code looked like was

<cfhttp url="#site#" method="post" result="page">
  <cfhttpparam type="cgi" name="Cookie" value="userid=01234">
</cfhttp>

I'm not exactly sure how type="cookie" works since in the ColdFusion 8 documentation it shows this as an example of using the type="cookie"

<cfhttpparam type="cookie" name="test" value="my cookie">
<cfoutput>#cookie.test#</cfoutput>

If someone knows what's going on please explain in the comments section.

1 response to “Passing cookie values in cfhttp”

Categories

Monthly Archives

Feeds