Skip to main content
Ben Nadel at the New York ColdFusion User Group (May. 2009) with: Mark Drew and Gert Franz
Ben Nadel at the New York ColdFusion User Group (May. 2009) with: Mark Drew Gert Franz

CFHTTPSession.cfc Gets Request / Response Logging

By
Published in Comments (10)

I have added logging to my CFHTTPSession.cfc ColdFusion component. For those of you who don't know what CFHTTPSession.cfc is, it's a ColdFusion component that can be used to perform multiple CFHTTP requests to the same domain. The beauty behind this request wrapper is that CFHTTPSession.cfc automatically parses, stores, and re-posts any cookies that were returned in any given request. In doing so, it allows the programmer to easily maintain an actual user session across successive CFHTTP requests.

Now, when you instantiate the CFHTTPSession.cfc class, you have the option to pass in a full log file path. If you do so, then each request and each response is appended to the given TXT file. This should make debugging the request / response cycle much easier.

For more information, see my CFHTTPSession.cfc project page.

Reader Comments

28 Comments

Hey Ben, I had glanced at this before but used some of my own functionality. Now in trying to refactor some code I'm giving it an actual try out. So far it is very easy to use and quite helpful.

I did find a minor bug when trying to manually set the user agent. The SetUserAgent function accepts one argument of name "Value".

However, the function refers to ARGUMENTS.UserAgent. I think that argument name is meant to be UserAgent. (Line 978).

Thanks for the awesome work you do.

12 Comments

Thanks again for your work on this, I have found this component to be wonderfully useful for something CF doesn't handle very well out of the box. It's also taught me quite a bit about how browsers interact with servers as well.

2 Comments

Love your code. I think I might be using this cfc wrong. here is my example:

cfset objResponse = objHttpSession.NewRequest()
i can see the cookies in
cfdump objResponse.responseheader['set-cookie']
and in
objHttpSession.getCookies()

but if i objHttpSession.AddCookie('TESTING', 'tester')
and then try
objHttpSession.getCookies()
i dont see TESTING

am i using this wrong?

Thanks, Jim

15,841 Comments

@Jim,

When you "Add" cookies or URL parameters or FORM parameters, they are send with the next request. Basically, under the hood, when you call things like AddUrl() and AddFile() it's building up a collection of CFHttpParams to be sent along with the next request.

Does that help at all?

2 Comments

@Ben Nadel,

Thank you for getting back so quickly! That helps. I have a site with a lot of js setting cookies so it makes it hard to mimic a web user, but your cfc makes things much easier. Thank you.

Jim

10 Comments

@Jim -

You might also want to take a look at CFX_HTTP5.

http://www.cftagstore.com/tags/cfxhttp5.cfm

It will easily handle cookies/sessions and a bunch more. It's also very, very fast and makes some stuff that is harder to do in CFHTTP much easier.

I'm not affiliated with the product in any way but have used it for several years and they continue to update it and add new stuff along the way. It's paid for itself many times over.

1 Comments

@Ben

Just sent you an e-mail through your contact form. I think I might have identified an incorrect behavior in how cookies are set within CFHTTPSession. Hope it's helpful.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel