Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
cfhttp head - Check if url is returning any response. Prevent freezing of website. like ping in coldfusion
Does a URL exist? Checks that host exists and for
404 status code.
<cffunction name="urlExists" output="no" returntype="boolean">
<!--- Accepts a URL --->
<cfargument name="u" type="string" required="yes">
<!--- Attempt to retrieve the URL --->
<cfhttp method="head" url="#ARGUMENTS.u#" resolveurl="no" throwonerror="no" timeout="2" />
<cfreturn not ( NOT IsDefined("cfhttp.responseheader.status_code") OR cfhttp.responseheader.status_code EQ "404" ) >
<cfcatch type="any">
<cfreturn false /><!--- failed to test file location --->
<cfset checkMe = IIF( urlExists( loremUrl ), DE( valA ), DE( valB ) ) />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.