Using the CFHTTP Get Method

You use Get to retrieve text and binary files from a specified server. The examples below illustrate a few common GET operations.

Note To retrieve a file and store it in a variable:
  1. Open a new file in Studio.
  2. Modify the file so that it appears as follows:
    <CFHTTP METHOD="Get"
        URL="http://www.allaire.com/index.cfm"
        RESOLVEURL="Yes">
    
    <CFOUTPUT>
        #CFHTTP.FileContent# <BR>
    </CFOUTPUT>
    
  3. Save the file as getwebpage.cfm in myapps under your Web root directory and view it in your browser.

Code Review
Code Description
<CFHTTP METHOD="Get"
URL="http://www.allaire.com/index.cfm"
RESOLVEURL="Yes">
Get the page specified in the URL and make the links absolute instead of relative..
<CFOUTPUT>
    #CFHTTP.FileContent# <BR>
</CFOUTPUT>
Display the page, which is stored in the variable CFHTTP.FileContent, in the browser.

Note To get a Web page and save it in a file:
  1. Open a new file in Studio.
  2. Modify the file so that it appears as follows:
    <CFHTTP
        METHOD = "get"
        URL="http://www.allaire.com/index.cfm"
        PATH="c:\mine"
        FILE="allaireindex.cfm">
    
  3. Change the path from c:\mine to point to a path on your hard drive.
  4. Save the file as savewebpage.cfm and view it in your browser.

Code Review
Code Description
<CFHTTP
    METHOD = "get"
    URL="http://www.allaire.com/index.cfm"
    PATH="c:\mine"
    FILE="allaireindex.cfm">
Get the page specified in the URL and save it in the file specified in PATH and FILE. Note that when the PATH and FILE attributes are used, the RESOLVEURL attribute is ignored, even if present.

Note To get a binary file and save it:
  1. Open a new file in Studio.
  2. Modify the file so that it appears as follows:
    <CFHTTP
        METHOD="Get"
        URL="http://maximus/downloads/quakestuff/q2_test.zip"
        PATH="c:\quake2\install"
        FILE="quake2beta.zip">
    
    <CFOUTPUT>
        #CFHTTP.MimeType#
    </CFOUTPUT>
    
  3. Change the URL to point to a binary file you want to download.
  4. Change the path to point to a path on your hard drive.
  5. Save the file as savebinary.cfm in myapps under your Web root directory and view it in your browser.

Code Review
Code Description
<CFHTTP
    METHOD="Get"
    URL="http://maximus/downloads/quakestuff/
q2_test.zip"
    PATH="c:\quake2\install"
    FILE="quake2beta.zip">
Get a binary file and save it in the PATH and FILE specified.
<CFOUTPUT>
    #CFHTTP.MimeType#
</CFOUTPUT>
Display the MIME type of the file.