User Guide

332 Chapter 18 Interacting with Remote Servers
Using cfhttp to Interact with the Web
The cfhttp tag, which enables you to retrieve information from a remote server, is
one of the more powerful tags in the CFML tag set. You can use one of two methods
to interact with a remote server using the
cfhttp tag: Get or Post.
Using the Get method, you can only send information to the remote server
directly in the URL. This method is often used for a one-way transaction in which
cfhttp retrieves an object.
By comparison, the Post method can pass variables to a ColdFusion page or CGI
program, which processes them and returns data to the calling page. The calling
page then displays or further processes the data that was received. For example,
when you use cfhttp to Post to another ColdFusion page, that page does not
display. It processes the request and returns the results to the original
ColdFusion page, which then uses the information as appropriate.
Using the cfhttp Get Method
You use Get to retrieve files, including text and binary files, from a specified server.
The retrieved information is stored in a special variable,
cfhttp.fileContent. The
following examples illustrate a few common Get operations.
To retrieve a file and store it in a variable:
1 Open a new file in ColdFusion Studio.
2 Modify the file so that it appears as follows:
<cfhttp method="Get"
url="http://www.ci.newton.ma.us/main.htm"
resolveurl="Yes">
<cfoutput>
#cfhttp.FileContent# <br>
</cfoutput>
3 (Optional) Replace the url attribute value with the URL of a file you want to get.
4 Save the file as
getwebpage.cfm in myapps under your Web root directory and
view it in your browser.