For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Interacting with Remote Servers / 

Using cfhttp to interact with the web

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

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.

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.adobe.com"
    resolveurl="Yes">
    <cfoutput>
    #cfhttp.FileContent# <br>
    </cfoutput>

    </body>
    </html>

  2. (Optional) Replace the value of the url attribute with another URL.
  3. Save the file as get_webpage.cfm in the myapps directory under your web_root and view it in the web browser.The browser loads the web page specified in the url attribute.
Reviewing the code

The following table describes the code and its function:

Code

Description

 

<cfhttp method="Get" url="http://www.adobe.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 cfhttp.fileContent, in the browser.

Get a web page and save it in a file
  1. Create a ColdFusion page with the following content:

    <html>
    <head>
    <title>Use Get Method</title>
    </head>
    <body>

    <cfhttp
    method = "Get"
    url="http://www.adobe.com/software"
    path="c:\temp"
    file="adobe_software.htm">
    </body>
    </html>

  2. (Optional) Replace the value of the url attribute with another URL and change the filename.
  3. (Optional) Change the path from C:\temp to a path on your hard drive.
  4. Save the page as save_webpage.cfm in the myapps directory under your web_root directory.
  5. Go to the specified path and view the file that you specified in a text editor (using the values specified in step 1, the path is C:\temp\macr_software.htm).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 could include.
Reviewing the code

The following table describes the code and its function:

Code

Description

 

<cfhttp
method = "Get"
url="http://www.adobe.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 path and file attributes.When you use the path and file attributes, ColdFusion ignores any resolveurl attribute. As a result, frames and other included files cannot appear when you view the saved page.

Get a binary file and save it
  1. Create a ColdFusion page with the following content:

    <cfhttp
    method="Get"
    url="http://www.adobe.com/adobe/accessibility/images/spotlight.jpg"
    path="c:\temp"
    file="My_SavedBinary.jpg">
    <cfoutput>
    #cfhttp.MimeType#
    </cfoutput>

  2. (Optional) Replace the value of the url attribute with the URL of a binary file that you want to download.
  3. (Optional) Change the path from C:\temp to a path on your hard drive.
  4. Save the file as save_binary.cfm in the myapps directory under your web_root and open it in the web browser to view the MIME type.
  5. (Optional) Verify that the binary file now exists at the location you specified in the path attribute.
Reviewing the code

The following table describes the code and its function:

Code

Description

 

<cfhttp method="Get" url="http://www.adobe.com/adobe/accessibility/images/spotlight.jpg" path="c:\temp" file="My_SavedBinary.jpg">

 

Get a binary file and save it in the path and file specified.

 

<cfoutput>
#cfhttp.MimeType#
</cfoutput>

Display the MIME type of the file.

Note: Prior to ColdFusion 11, CFHTTP could only execute URLs which had either no authentication in the web server (anonymous access)  or Basic authentication (in which case the authtype="basic" attribute must be used with username and password attributes.) ColdFusion 11 added support for Windows NTLM authentication, in which case the the authtype="ntlm" attribute must be used which has associated domain and workstation attributes.)

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices