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:
cfhttp
retrieves an object.
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.
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.
<html> <head> <title>Use Get Method</title> </head> <body> <cfhttp method="Get" url="http://www.macromedia.com" resolveurl="Yes"> <cfoutput> #cfhttp.FileContent# <br> </cfoutput> </body> </html>
url
attribute with another URL.
The browser loads the web page specified in the url
attribute.
The following table describes the code and its function:
Code | Description |
---|---|
<cfhttp method="Get" url="http://www.macromedia.com" resolveurl="Yes"> |
Get the page specified in the URL and make the links absolute instead of relative so that they appear properly. |
<cfoutput> #cfhttp.FileContent# <br> </cfoutput> |
Display the page, which is stored in the variable |
<html> <head> <title>Use Get Method</title> </head> <body> <cfhttp method = "Get" url="http://www.macromedia.com/software" path="c:\temp" file="macr_software.htm"> </body> </html>
url
attribute with another URL and change the filename.
The saved file does not appear properly in your browser because the Get operation saves only the specified web page HTML. It does not save the frame, image, or other files that the page might include.
The following table describes the code and its function:
Code | Description |
---|---|
<cfhttp method = "Get" url="http://www.macromedia.com/software" path="c:\temp" file="macr_software.htm"> |
Get the page specified in the URL and save it in the file specified by the When you use the |
<cfhttp method="Get" url="http://www.macromedia.com/macromedia/accessibility/images/ spotlight.jpg" path="c:\temp" file="My_SavedBinary.jpg"> <cfoutput> #cfhttp.MimeType# </cfoutput>
url
attribute with the URL of a binary file that you want to download.
path
attribute.
The following table describes the code and its function:
Code | Description |
---|---|
<cfhttp method="Get" url="http://www.macromedia.com/macromedia/accessibility/images/spotlight.jpg" path="c:\temp" file="My_SavedBinary.jpg"> |
Get a binary file and save it in the |
<cfoutput> |
Display the MIME type of the file. |