BackUp LevelNext

Using the CFHTTP Post Method

Use the Post method to send cookie, form, CGI, URL, and file variables to a specified ColdFusion page or CGI program. For Post operations , the CFHTTPPARAM tag must be used 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.

Example: Pass variables to a ColdFusion page

The following example 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.

Sample file: posttest.cfm

<CFHTTP METHOD="Post"
    URL="http://housebeat/cfdocs/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>

Sample file: server.cfm

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>

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

Example: Returns results of CGI program

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

<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>


BackUp LevelNext

allaire

AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.