Skip to content

Instantly share code, notes, and snippets.

@cflove
Created December 31, 2013 15:10
Show Gist options
  • Select an option

  • Save cflove/8198147 to your computer and use it in GitHub Desktop.

Select an option

Save cflove/8198147 to your computer and use it in GitHub Desktop.
Grab page over http, like in cfhttp. Had to fetch directory index from an old Fedora 4 box and cfhttp did not return it. This seems to do the trick.
<cffunction name="httppage" access="public" returnType="any" output="no">
<cfargument name ="source" type="any" required="true"/>
<cfset local.urlconnection = createObject("java", "java.net.URL").init(javaCast('string',arguments.source))>
<cfset local.Connection = local.urlconnection..openConnection() />
<cfset local.Connection.connect() />
<cfset local.InputStreamReader = createObject("java", "java.io.InputStreamReader").init(local.Connection.getInputStream()) />
<cfset local.BufferedReader = createObject("java", "java.io.BufferedReader").init(local.InputStreamReader) >
<cfset local.Page = arrayNew(1) />
<cfloop condition="#yesNoFormat(local.BufferedReader.ready())#">
<cfset arrayAppend(local.Page,local.BufferedReader.readLine())>
</cfloop>
<cfreturn local.Page>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment