808
Chapter 36: Interacting with Remote Servers
About interacting with remote servers
Transfer protocols are mechanisms for moving files and information from a source to one or more
destinations. Two of the more popular protocols are the Hypertext Transfer Protocol (HTTP) and
the File Transfer Protocol (FTP). ColdFusion has the
cfhttp
and
cfftp
tags that let you use
these protocols to interact with remote servers.
The
cfhttp
tag lets you receive a web page or web-based file, just as a web browser uses HTTP to
transport web pages. When you type a URL into a web browser, you make an HTTP request to a
web server. With the
cfhttp
tag, you can display a web page, send variables to a ColdFusion or
CGI application, retrieve specialized content from a web page, and create a ColdFusion query
from a text file. You can use the Get or Post methods to interact with remote servers.
The
cfftp
tag takes advantage of FTP’s main purpose—transporting files. Unlike HTTP, FTP
was not designed to interact with other servers for processing and interacting with data. Once you
establish an FTP connection with the
cfftp
tag, you can use it to upload, download, and manage
files and directories.
Using cfhttp to interact with the web
The
cfhttp
tag, which lets you 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—Get or Post—to interact
with a remote server using the
cfhttp
tag:
•
Using the Get method, you can only send information to the remote server in the URL. This
method is often used for a one-way transaction in which
cfhttp
retrieves an object.
•
Using the Post method, you can pass variables to a ColdFusion page or CGI program, which
processes them and returns data to the calling page. The calling page then appears or further
processes the data that was received. For example, when you use
cfhttp
to Post to another
ColdFusion page, that page does not appear. 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 show
several common Get operations.
To retrieve a file and store it in a variable:
1
Create a ColdFusion page with the following content:
<html>
<head>
<title>Use Get Method</title>
</head>
<body>
<cfhttp
method="Get"
url="http://www.macromedia.com"
resolveurl="Yes">
<cfoutput>
#cfhttp.FileContent# <br>
</cfoutput>
Summary of Contents for ColdFusion MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......