CFLib.org – Common Function Library Project

HTTPGet(u)

Last updated November 11, 2002

author

Ben Forta

Version: 1 | Requires: CF5 | Library: NetLib

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:

<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:

/**
 * 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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson