Ask Ben: Grabbing World Of Warcraft Data With ColdFusion And CFHTTP

<!---
	Store the user agent that I am using with my browser
	(you're damn right I use FireFox!). I am breaking this
	data into two lines for display purposes ONLY.
--->
<cfset strUserAgent = (
	"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; " &
	"rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"
	) />
 
 
<!---
	Get the target URL that we are grabbing. This page
	provides an XML document with an XSL transformation
	processing instruction. We want to grab the XML without
	the data being transformed into HTML. I am breaking this
	data into two lines for display purposes ONLY.
--->
<cfset strURL = (
	"http://armory.worldofwarcraft.com/character-sheet.xml" &
	"?r=Bloodhoof&n=Castlereagh"
	) />
 
 
<!---
	Grab the target page without sending across any user agent
	information. When we do this, ColdFusion automatically puts
	in "ColdFusion" as the browser's user agent value.
--->
<cfhttp
	url="#strURL#"
	method="GET"
	result="objHTTP"
	/>
 
 
<!---
	Now, let's grab the same page, but this time, instead of
	letting ColdFusion send over a default user agent, we are
	going to explicitly define what user agent the HTTP reuqest
	should announce.
--->
<cfhttp
	url="#strURL#"
	method="GET"
	result="objHTTPWithUA"
	useragent="#strUserAgent#"
	/>
 
 
 
<!---
	Let's output the leading characters of the request without
	the user agent value.
--->
<p>
	<strong>Request With ColdFusion User Agent</strong>:
</p>
 
<p>
	#HtmlEditFormat(
		Left( objHTTP.FileContent, 500 )
		)#
</p>
 
 
<!---
	Let's output the leading characters of the request in which
	we explicitly defined the FireFox user agent.
--->
<p>
	<strong>Request With FireFox User Agent</strong>:
</p>
 
<p>
	#HtmlEditFormat(
		Left( objHTTPWithUA.FileContent, 500 )
		)#
</p>

For Cut-and-Paste