In PHP there’s a simple function called file_get_contents, and if I wanted to retrieve and display the 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 retrieve the output of an external site into a string variable (and then manipulate it accordingly)?
The simplest cross-engine equivalent of what you’ve written is:
You can specify an alternative to the auto-created cfhttp variable like this:
Both of those will work in all major CFML engines (Adobe CF, OpenBD, Railo).
You can see the full set of options (methods,params,proxy settings,etc) in the cfhttp documentation, and to see the full response struct, just use
<cfdump var=#cfhttp#/>after a call (or whatever the result var is named).There is an extra option which works with Railo, which is more directly what you’ve got in PHP, Like this:
This works because Railo has Resources (virtual filesystems), so everywhere you can do a file operation, you can use various virtual filesystems, including HTTP, ZIP, RAM, and others.
(Adobe have started adding virtual filesystems also, but I think so far only support RAM, so this doesn’t work there.)