Executes HTTP POST and GET operations on files. You can execute standard GET operations and create a query object from a text file. POST operations upload MIME file types to a server, or post cookie, formfield, URL, file, or CGI variables directly to a server.
Forms tags, Internet Protocol tags
<cfhttp url = "hostname" port = "port_number" method = "get_or_post" username = "username" password = "password" name = "queryname" columns = "query_columns" firstrowasheaders = "yes" or "no" path = "path" file = "filename" delimiter = "character" textQualifier = "character" resolveURL = "yes" or "no" proxyServer = "hostname" proxyPort = "port_number" userAgent = "user_agent" throwOnError = "yes" or "no" redirect = "yes" or "no" timeout = "timeout_period" charset = "character set"> </cfhttp>
cfftp, cfhttpparam, cfldap, cfmail, cfmailparam, cfpop
firstrowasheaders attribute is new.
charset attribute is new.
If this value includes the substring "https" (which indicates that the object of the request is a secure server) but does not include a port number, the default value of the port attribute is 443. (If the URL value includes a port number, its value overrides the value of port.)
For the ColdFusion Administrator timeout and the URL timeout to take effect, you must enable the timeout in the ColdFusion Administrator, Server Settings page. For more information, see Administering ColdFusion MX.
The cfhttp tag returns data in variables. For example, if you specify a URL that points to a text or binary file in a cfhttp method = "get" operation, the file is downloaded and stored in a ColdFusion variable or file.
mimeType variable is available for all file manipulations. These variables can be accessed in this way:
#cfhttp.fileContent#
#cfhttp.mimeType##cfhttp.header##cfhttp.responseHeader[http_header_key]#
The responseHeader variable is returned as a CFML structure; the others, as strings.
To download a file in a ColdFusion page so that a query can be built using the file, the file must be either comma- or tab-delimited. Macromedia recommends that you include text qualification. The file is parsed and an appropriate query is built from it. You can specify columns in the attribute list so the client can override the columns specified in the file.
There is error checking within the tag that prevents a user from entering an invalid column name, or using an invalid column name that was specified in the original file. If an illegal filename is encountered, the illegal characters are stripped. This action could produce duplicate column names, so duplicate columns are renamed and inserted into the query header.
The query has all of the functionality of a standard cfquery object, as follows:
cfhttpparam tags within a cfhttp tag. The browser can be pointed to a URL that specifies a CGI executable or a ColdFusion page. Because cfhttpparam tags can be nested, you can construct a multipart/form-data style post. A file content variable is created; you can use it in a cfoutput tag. If path and file attributes are specified, the data returned from the server is saved to the specified location.
cfhttp supports Windows NT Basic Authentication for GET and POST operations. However, Basic Authentication does not work if your web server has Windows NT Challenge/Response (Microsoft IIS) enabled.cfhttp uses SSL to negotiate secure transactions.cfhttp.statuscode: cfhttp provides the cfhttp.statuscode variable for access to the HTTP error string associated with the error if the throwOnError attribute is set to No (or if it is not specified, because it defaults to No).
The cfhttp tag returns the following variables:
Terminate a cfhttp method = "post" operation with </cfhttp>.
<!--- This example shows the use of CFHTTP to pull information dynamically from
the snippets directory --->
<p>This view-only example shows the ability of CFHTTP to pull the contents of
a web resource from the Internet or from a local directory.
<!---
<form action="index.cfm" method="POST">
Try entering a URL for the tag to return:
<input type="Text" size="25" name="urladdress"
value="http://www.macromedia.com">
<input type="Submit" name="" value="get page">
</form>
<!----- sets a default value for a URL to retrieve ----->
<cfparam name="urladdress"
default="http://localhost/cfdocs/index.htm">
<!--- if we have passed a url address in the form, display the address --->
<cfif IsDefined("form.urladdress") is True>
<!--- do simple error check to avoid crashing the tag --->
<cfif Trim(Form.urladdress) is ""
or Trim(Form.urladdress) is "http://">
<!--- if error condition tripped, set alternative --->
<cfset urlAddress ="http://localhost/cfdocs/index.htm">
<h4>because you entered no url or an empty string, the tag will
return the following address: http://localhost/cfdocs/index.htm</h4>
<cfelse>
<!--- otherwise use address passed from form --->
<cfset urlAddress = form.urladdress>
</cfif>
<!--- use CFHTTP tag to get the file content represented by urladdress --->
<cfhttp url="#urladdress#"
method="GET" resolveurl="YES">
</cfhttp>
<cfelse>
<!--- the first time through, retrieve a URL that we know exists ---->
<cfhttp url="http://localhost/cfdocs/index.htm"
method="GET" resolveurl="YES">
</cfhttp>
</cfif>
<!---- Now, output the file, including the mimetype and content ------>
<h3>Show the file</h3>
<cfoutput>
<p>Your file was of type: #CFHTTP.MimeType#
<p>#HTMLCodeFormat(CFHTTP.FileContent)#
</cfoutput> --->
ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6
Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt154.htm
Comments
fusebox_steve said on Jul 1, 2002 at 10:20 PM : rbils@amkor.com said on Jul 16, 2002 at 3:41 AM : ctina said on Jul 22, 2002 at 2:24 PM : ctina said on Jul 22, 2002 at 7:06 PM : alex.lake said on Sep 5, 2002 at 3:49 PM : rnielsen said on Sep 20, 2002 at 2:29 PM : carehart@systemanage said on Dec 31, 2002 at 3:19 PM : carehart@systemanage said on Jan 2, 2003 at 8:14 AM : carehart@systemanage said on Jan 2, 2003 at 8:15 AM : mesh said on Jan 14, 2003 at 11:15 AM : saro28 said on Mar 6, 2003 at 5:58 PM : alinear said on Jun 6, 2003 at 12:09 PM : hlichtin said on May 8, 2003 at 10:20 AM : hlichtin said on May 8, 2003 at 10:23 AM : jedimaster said on May 5, 2003 at 3:32 PM : phantem said on May 19, 2003 at 6:03 PM : TheoPeters said on Aug 12, 2003 at 3:11 PM :