CFLib.org – Common Function Library Project

HTTPGet(u)

Last updated November 11, 2002

Version: 1 | Requires: ColdFusion 5 | Library: NetLib

 
Rated 2 time(s). Average Rating: 3.0

Description:
UDF equivelant of <CFHTTP>, pass it a URL and it'll return the stream. Does not support passing parameters or fields. Requires a complete URL with the protocol (the http://).

Return Values:
Returns a string.

Example:

view plain print about
<cfset page = HTTPGet("http://www.macromedia.com")>
<cfset page = HTMLEditFormat(page)>
Here is a portion of the HTML:
<p>
<cfloop index="x" from=1 to=5>
    <cfset line = listGetAt(page,x,chr(10))>
    <cfoutput>#line#<br></cfoutput>
</cfloop>

Parameters:

Name Description Required
u The URL to fetch. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * UDF equivelant of &lt;CFHTTP&gt;
 * 
 * @param u      The URL to fetch. (Required)
 * @return Returns a string. 
 * @author Ben Forta (ben@forta.com) 
 * @version 1, November 11, 2002 
 */

function HTTPGet(u) {
   // Variables
   var urlclass="";
   var page="";
   var stream="";
   var c="";
   var output="";
   
   // Init class
   urlclass=CreateObject("java""java.net.URL");

   // Get page
   page=urlclass.init(u);

   // Get stream
   stream=page.getContent();
    
   // Display it
   for (c=stream.read(); c GT 0; c=stream.read())
   {
      output=output&chr(c);
   }

   // don't forget this part
   stream.close();
   
   return output;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
15 day(s) ago

James Sleeman James Sleeman added
quickSort
25 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
28 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson