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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson