Retrieving Information

cfhttp uses the HTTP GET method to initiate a one-way request for information from a remote server. The transaction mimics the one that a standard web browser uses to request a web page. The only difference is that in the case of cfhttp, the requested page is stored in a ColdFusion variable or in a query object, as opposed to being displayed in the user’s browser. Let’s look at the different ways in which you can use cfhttp to request information from a remote server.

Saving Information to a Variable

In its most simplistic form, cfhttp can grab an entire file (either plain text or HTML) and store it in a single variable called cfhttp.FileContent. You can access and manipulate the information stored in cfhttp.FileContent as you can with any other ColdFusion variable. cfhttp.FileContent is only one return variable made available by the cfhttp tag. All cfhttp operations return a structure called cfhttp that contains information returned by the target server. Depending on the HTTP operation performed (as defined by the method attribute) as well as the response returned by the target server, the cfhttp structure may or may not contain values for the following keys:

cfhttp.charset

Character encoding specified by the response Content-Type header.

cfhttp.errorDetail

In the event of a connection failure, contains details related to the failure. If no failure occurs, this key contains an empty string.

cfhttp.fileContent

Contains the response body resulting from ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.