ColdFusion 9.0 Resources |
Using the CF.http functionThe CF.http function returns an object that contains properties, also known as attributes. You reference these attributes to access the contents of the file returned, header information, HTTP status codes, and so on. The following table shows the available properties:
Referencing HTTP Post parameters in the CF.http functionTo pass HTTP Post parameters in the CF.http function, construct an array of objects and assign this array to a variable named params. The following arguments can only be passed as an array of objects in the params argument of the CF.http function:
In the following example, the CF.http function passes HTTP Post parameters in an array of objects: function postWithParamsAndUser() { // Set up the array of Post parameters. These are just like cfhttpparam tags. params = new Array(); params[1] = {name:"arg2", type:"URL", value:"value2"}; url = "http://localhost:8500/"; // Invoke with the method, url, params, username, and password result = CF.http("post", url, params, "karl", "salsa"); return result.get("Filecontent"); } Using the CF.http Post methodYou use the Post method to send cookie, form field, CGI, URL, and file variables to a specified ColdFusion page or CGI program for processing. For POST operations, use the params argument for each variable that you post. The Post method passes data to a specified ColdFusion page or an 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 page to which form data is passed. You use the Post method in the CF.http function in a similar way. However, with the CF.http function, the page that receives the Post does not display anything. See the following example: function postWithParams() { // Set up the array of Post parameters. These are just like cfhttpparam tags. // This example passes formfield data to a specified URL. params = new Array(); params[1] = {name:"Formfield1", type:"FormField", value:"George"}; params[2] = [name:"Formfield2", type:"FormField", value:"Brown"}; url = "http://localhost:8500/"; // Invoke CF.http with the method, url, and params result = CF.http("post", url, params); return result.get("Filecontent"); } Using the CF.http Get methodYou use the Get method to retrieve files, including text and binary files, from a specified server. You reference properties of the object returned by the CF.http function to access things like file content, header information, MIME type, and so on. The following example uses the CF.http function to show a common approach to retrieving data from the web: // Returns content of URL defined in url variable // This example uses positional argument style function get() { url = "http://www.adobe.com/software/coldfusion/"; //Invoke with just the url argument. Get is the default. result = CF.http(url); return result.get("Filecontent"); } For more information about CF.http function properties, see CF.http in the CFML Reference. |