# Using the CFHTTP Post Method

Use the Post method to send cookie, form field, CGI, URL, and file variables to a specified ColdFusion page or CGI program. For Post operations, you must use the CFHTTPPARAM tag for each variable you want to post. Unlike the Get method, Post passes data to a specified ColdFusion page or to some executable that interprets the variables being sent and returns data.

For example, when you build an HTML form using the Post method, you specify the name of the program to which form data will be passed. Using the Post method in CFHTTP is exactly the same.

| To pass variables to a ColdFusion page:

1. Open a new file in Studio.
2. Modify the file so that it appears as follows:

       <CFHTTP METHOD="Post"
           URL="http://127.0.0.1/dwa_code/server.cfm"
           USERNAME="user1"
           PASSWORD="user1pwd">

           <CFHTTPPARAM TYPE="Cookie"
               VALUE="cookiemonster"
               NAME="mycookie6">
           <CFHTTPPARAM TYPE="CGI"
               VALUE="cgivar "
               NAME="mycgi">
           <CFHTTPPARAM TYPE="URL"
               VALUE="theurl"
               NAME="myurl">
           <CFHTTPPARAM TYPE="Formfield"
               VALUE="wbfreuh@allaire.com"
               NAME="emailaddress">
           <CFHTTPPARAM TYPE="File"
               NAME="myfile"
               FILE="c:\temp\cyberlogo.gif">
       </CFHTTP>

       <CFOUTPUT>
           #CFHTTP.filecontent#
           #CFHTTP.mimetype#
       </CFOUTPUT>

3. Replace the URL with one on your server.
4. Save the file as `server.cfm` in `myapps` under your Web root directory.

| To view the variables:

1. Create a new file in Studio.
2. Modify the file so that it appears as follows:

       You have POSTed to me.<BR>
       <CFFILE DESTINATION="c:\temp\junk"
           NAMECONFLICT="Overwrite"
           FILEFIELD="myfile"
           ACTION="Upload"
           ATTRIBUTES="Normal">

       <CFOUTPUT>
           The URL variable is: #url.myurl# <BR>
           The Cookie variable is: #cookie.mycookie6# <BR>
           The CGI variable is: #cgi.mycgi#. <BR>
           The Formfield variable is: #form.myformfield#. <BR>
       </CFOUTPUT>

3. Replace c:\temp\junk with a path and filename on your hard drive.
4. Save the file as `posttest.cfm` in `myapps` under your Web root directory.

This example uses the CFFILE tag to upload the contents of the file variable to `c:\temp\junk.`

It passes the five supported variable types to the page specified in the URL attribute. The page that receives this data is also shown. It returns the value of the variables which appears in the client's browser. This example uses the CFFILE tag in the page that receives the Posted variables to upload the contents of the file variable to `c:\temp\junk.`

The CFOUTPUT section in `posttest.cfm` references the `CFHTTP.FileContent` variable, which is used to display the output from the `server.cfm` file. If the `CFHTTP.FileContents` variable were left out, the browser output would be limited to the contents of the `posttest.cfm` file.

| To return resuls of a CGI program:

1. Create a new file in Studio.
2. Modify the file so that it appears as follows:

       <CFHTTP METHOD="Post"
           URL="http://www.thatsite.com/search.exe"
           RESOLVEURL="Yes">

           <CFHTTPPARAM TYPE="Formfield"
               NAME="search"
               VALUE="hello">

       </CFHTTP>

       <CFOUTPUT>
           #CFHTTP.MimeType#<BR>
           Length: #len(cfhttp.filecontent)# <BR>
           Content: #htmlcodeformat(cfhttp.filecontent)#<BR>
       </CFOUTPUT>

3. Save the file as`getcgivars.cfm` in `myapps` under your Web root directory.

This example runs a CGI program, `search.exe`, that searches the site and returns the hits on the value specified in VALUE.