use cfhttp in cfscript version

With the cfhttp Tag (Definition: „Generates an HTTP request and handles the response from the server“) you can easily get content from other URIs.
Here’s a short example how to use cfhttp inside in CFScript, that worked for me very well.
Please note that this example works properly with getting content from username / password protected URIs, too. I’ve tested my Code with Railo 3.3.1 final


//get cfhttp result
string function getCfHttpResult(required string targetUri="") output="false" access="private" hint="returns http result for a given uri" {
try {
http = new http();
http.setMethod("get");
http.setURL("#arguments.targetUri#");
http.setUsername("#getUsername()#");
http.setPassword("#getPassword()#");.
ret = http.send().getPrefix().FileContent;
}
catch (any e) {
ret = 0;
}
}

Schreibe einen Kommentar