If-Modified-Since and CFML Part II
Now that you know how handle HTTP requests with the If-Modified-Since header in ColdFusion, lets take a look at how you might write a HTTP client using CFHTTP that sends If-Modified-Since headers:
<cfset lastCheckDate = GetHttpTimeString(DateAdd("d", -7, Now()))>
<cfhttp url="http://www.petefreitag.com/rss/" method="get" >
<cfhttpparam type="header" name="If-Modified-Since" value="#lastCheckDate#">
</cfhttp>
<cfif cfhttp.responseheader.status_code EQ 304>
<h1>Content HAS NOT Changed since <cfoutput>#lastCheckDate#</cfoutput></h1>
<cfelseif cfhttp.responseheader.status_code EQ 200>
<h1>Content has changed since <cfoutput>#lastCheckDate#</cfoutput></h1>
</cfif>
<cfdump var="#cfhttp#">
I just use the cfhttpparam tag to send the If-Modified-Since value. Again you need to format your date with GetHttpTimeString()
The date I supplied in this example is one week ago. You can remove the DateAdd, and just use Now() to check and see if the file has been modified.
Some servers may reject a date that is greater than their server time, so keep that in mind when testing.
Related Entries
- If-Modified-Since and CFML Part III - February 22, 2005
- Supporting If-Modified-Since HTTP header in CFML - February 18, 2005
- 8 Ways to Save Bandwidth on your RSS Feed - July 12, 2007
- Parsing RSS 1.0 with ColdFusion MX - April 8, 2004
- RSS and XPath - April 8, 2004
Trackbacks
Trackback Address: 236/5A81DFFB02B8FB5291307D0B88A41816
Comments
On 02/20/2005 at 4:14:55 AM EST Roger Benningfield wrote:
1
Pete: This must be my night to be a pain in the butt. :)
In terms of RSS, you should generally avoid (read: almost never) send an If-Modified-Since that isn't derived from a Last-Modified you've previously received from the target server. Doing otherwise will lead to highly unpredictable results.
Post a Comment
Recent Entries
- Cache Template in Request Setting Explained
- What Version of Java is ColdFusion Using?
- ColdFusion 9 Performance Brief from Adobe
- Request Filtering in IIS 7 Howto
- J2EE Session Cookies on ColdFusion / JRun
- Hands on ColdFusion Security Training
- ColdFusion 9 Solr Vulnerability - Are you at Risk?
- FCKEditor Year 2010 Bug for Firefox 3.6 with ColdFusion
In terms of RSS, you should generally avoid (read: almost never) send an If-Modified-Since that isn't derived from a Last-Modified you've previously received from the target server. Doing otherwise will lead to highly unpredictable results.



add to del.icio.us



