How do you extract HTML from an external website into a variable in ColdFusion?

PHP has a simple function called file_get_contents, and if I wanted to get and display HTML on, say, google.com, I would just do this:

<?php
$html = file_get_contents('http://www.google.com/');
echo $html;
?>

Is there an equivalent to this in ColdFusion? Can you get the output of an external site into a string variable (and then manage it accordingly)?

+3
source share
3 answers

The simplest cross-engine equivalent to what you wrote:

<cfhttp url="http://www.google.com/" />
<cfset html = cfhttp.FileContent />
<cfoutput>#html#</cfoutput>

You can specify an alternative to the automatically generated cfhttp variable as follows:

<cfhttp url="http://www.google.com/" result="Response" />
<cfset html = Response.FileContent />
<cfoutput>#html#</cfoutput>

Both of them will work in all major CFML mechanisms ( Adobe CF , OpenBD , Railo ).

(, , ..) cfhttp struct, <cfdump var=#cfhttp#/> ( , var).


, Railo, , PHP, :

<cfset html = FileRead('http://www.google.com/') />
<cfoutput>#html#</cfoutput>

, Railo ( ), , , , HTTP, ZIP, RAM .

(Adobe , , , .)

+10
<cfset destination = "http://www.google.com">
<cfhttp url = #destination# method = "post" result="httpResult">
<cfoutput>#httpResult.fileContent#</cfoutput>
+2
<cfhttp method="Get"
   url="127.0.0.1/blah.html"
   name="myvar">
 <cfdump var="#myvar#">
+1

Source: https://habr.com/ru/post/1754259/


All Articles