Executes HTTP POST and GET operations on files. POST operations upload MIME file types to a server, or post cookie, formfield, URL, file, or CGI variables directly to a server.
Returns an object containing properties that you reference to access data. For available properties returned by the CF.http function, see "Properties available with the CF.http object".
CF.http
({
method:"get or post",
url:"URL",
username:"username",
password:"password",
resolveurl:"yes or no",
params:arrayvar,
path:"path",
file:"filename"
})
| Arguments |
Req/Opt |
Description |
|---|---|---|
| method |
Required |
Two arguments are supported:
|
| url |
Required |
The absolute URL of the host name or IP address of server on which the file resides. The URL must include the protocol (http or https) and host name. |
| username |
Optional |
When required by a server, a username. |
| password |
Optional |
When required by a server, a password. |
| resolveurl |
Optional |
For Get and Post methods.
For GET and POST operations, if Yes, page reference that is returned into the Filecontent property has its internal URLs fully resolved, including port number, so that links remain intact. The following HTML tags, which can contain links, are resolved:
|
| params |
Optional |
HTTP parameters passed as an array of objects. Supports the following parameter types:
CF.http params are passed as an array of objects. The params argument is required for POST operations.For detailed information about each params argument, see "CF.http parameters" . |
| path |
Optional |
The path to the directory in which to store files. When using the path argument, the file argument is required. |
| file |
Optional |
Name of the file that is accessed. For GET operations, defaults to name specified in the url argument. Enter path information in the path attribute. |
You can code the CF.http function using named arguments or positional arguments. You can invoke all supported arguments using the named argument style, as follows:
CF.http({method:"method", url:"URL", username:"username", password:"password",
resolveurl:"yes or no", params:arrayvar, path:"path", file:"filename"});
Note: The named argument style uses curly braces {} to surround the function arguments.
Positional arguments let you use a shorthand coding style. However, not all arguments are supported for the positional argument style. Use the following schemas to code the CF.http function using positional arguments:
CF.http(url);
CF.http(method, url); CF.http(method, url, username, password); CF.http(method, url, params, username, password);
Note: When using positional arguments, do not use curly braces {}.
The following parameters can only be passed as an array of objects in the params argument in the CF.http function:
The CF.http function returns data as a set of object properties:
You access these attributes using the get function:
function basicGet()
{
url = "http://localhost:8100/";
// Invoke with just the url. This is an http get.
result = CF.http(url);
return result.get("Filecontent");
}
The following examples show a number of the ways to use the CF.http function:
function postWithNamedArgs()
{
// Set up the array of post parameters.
params = new Array();
params[1] = {name:"arg1", type:"FormField", value:"value1"};
params[2] = {name:"arg2", type:"URL", value:"value2"};
params[3] = {name:"arg3", type:"CGI", value:"value3"};
url = "http://localhost:8100/";
path = application.getContext("/").getRealPath("/");
file = "foo.txt";
result = CF.http({method:"post", url:url, username:"karl", password:"salsa",
resolveurl:true, params:params, path:path, file:file});
if (result)
return result.get("Statuscode");
return null;
}
// Example of a basic HTTP get operation
// Shows that HTTP Get is the default
function basicGet()
{
url = "http://localhost:8100/";
// Invoke with just the URL. This is an HTTP Get.
result = CF.http(url);
return result.get("Filecontent");
}
// Example showing simple array created to pass params arguments
function postWithParams()
{
// 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:8100/";
// Invoke with the method, url, and params
result = CF.http("post", url, params);
return result.get("Filecontent");
}
// Example with username and params arguments
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:8100/";
// Invoke with the method, url, params, username, and password
result = CF.http("post", url, params, "karl", "salsa");
return result.get("Filecontent");
}
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6
Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.