CFHTTPSession.cfc Gets Request / Response Logging

Posted April 13, 2009 at 9:56 AM by Ben Nadel

Tags: ColdFusion

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

Apr 17, 2009 at 3:02 PM // reply »
27 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.


Apr 17, 2009 at 4:40 PM // reply »
10,640 Comments

@Matt,

Awesome catch. Yes that is definitely a bug.


PJ
Apr 22, 2009 at 2:57 AM // reply »
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.


May 3, 2009 at 3:04 PM // reply »
10,640 Comments

@PJ,

Glad you're liking it :)


Jim
May 21, 2010 at 7:28 PM // reply »
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


May 21, 2010 at 9:01 PM // reply »
10,640 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?


Jim
May 24, 2010 at 2:41 PM // reply »
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


Jun 8, 2010 at 1:55 PM // reply »
10,640 Comments

@Jim,

Awesome my man :)


Jun 8, 2010 at 4:31 PM // reply »
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.


May 25, 2011 at 10:06 AM // reply »
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.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »
Feb 9, 2012 at 10:29 PM
Learning ColdFusion 9: Application-Specific Data Sources
@Ben, No offence, but if people were really wanting advanced features they would be using a platform like ASP.NET MVC. CFML is so structurally compromised as a tag-based scripting language that ... read »
Feb 9, 2012 at 10:03 PM
Subversion - Cleanup Failed To Process The Following Paths
@Leviaguirre, do you still have problems with this? ... read »