User Guide
180 Chapter 2: ColdFusion Tags
The HTTP protocol is the backbone of the World Wide Web and is used for every web
transaction. Because the
cfhttp tag can generate most types of requests, it provides significant
flexibility. Possible uses include:
• Interacting with dynamic web sites and services that are not available as web services. (Use the
the
cfinvoke tag to access SOAP web services.)
• Getting the contents of an HTML page or other file such as an image on a web server for use
in your CFML page or storage in a file.
• Sending a secure request to a server by specifying the https protocol in the url attribute.
• Using the POST method to send a multipart/form-data style post to any URL that can handle
such data and return results, including CGI executables or even other ColdFusion pages.
• Using the PUT method to upload files to a server that does not accept FTP requests.
This tag can, and for PUT and POST requests must, have a body that contains
cfhttpparam
tags. If this tag has
cfhttpparam tags, it must have a </cfhttp> end tag.
Variables returned by a cfhttp get operation
The cfhttp tag returns the following variables:
Name Description
cfhttp.charSet Response character character set (character encoding) specified by the
response Content-Type header.
cfhttp.errorDetail If the connection to the HTTP server fails, contains details about the
failure. For instance: "Unknown host: my.co.com"; otherwise, the empty
string
cfhttp.fileContent Response body; for example, the contents of a html page retrieved by a
GET operation. Empty if you save the response in a file.
cfhttp.header Raw response header containing all header information in a single string.
Contains the same information as the
cfhttp.responseHeader variable.
cfhttp.mimeType MIME type specified by the response Content-Type header; for
example, text/html.
cfhttp.responseHeader The response headers formatted into a structure. Each element key is
the header name, such as Content-Type or Status_Code. If there is more
than one instance of a header type, the type values are put in an array.
One common technique is to dynamically access the
cfhttp.responseHeader structure as a dynamic array; for example,
#cfhttp.resonseHeader[fieldVariable]#.
cfhttp.statusCode The HTTP status_code header value followed by the HTTP Explanation
header value, for example "200 OK".
cfhttp.text Boolean; True if the response body content type is text. ColdFusion
recognizes the response body as text if:
• the header does not specify a content type
• the content type starts with "text"
• the content type starts with "message"
• the content type is "application/octet-stream"