|
ColdFusion 9.0 Resources |
CF.httpDescriptionExecutes 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.) SyntaxCF.http
({
method:"get or post",
url:"URL",
username:"username",
password:"password",
resolveurl:"yes or no",
params:arrayvar,
path:"path",
file:"filename"
})
Arguments
UsageYou can write 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 syntax 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: Do not use curly braces {} with positional arguments.
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, as described in the following table:
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");
}
Note: For more information on using
server-side ActionScript, see Using
Server-Side ActionScript in the Developing ColdFusion Applications.
ExampleThe 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");
}
|