...

View Full Version : ASP Equivalent of file_get_contents?



Pennimus
10-10-2007, 02:46 PM
I'm having no luck finding this, everything I see seems far too complex for this simple operation. Can some bright spark point me in the right direction?

Here's the PHP:



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

Daemonspyre
10-10-2007, 03:04 PM
Unfortunately, there isn't a truly easy way to do this in ASP. At least not that I know of.

You could use AJAX to pull the file over to the server, then use the Scripting.FileSystemObject to write the page to a string.

Complicated it is, as M$ never thought that anyone would ever want to use this feature...

Sorry...

Spudhead
10-10-2007, 04:21 PM
I might be wrong, but wouldn't this do it:


function file_get_contents(sURL)
dim xmlhttp, sResult
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET",sURL, false
xmlhttp.send sURL
sResult = xmlhttp.ResponseText
set xmlhttp = nothing
file_get_contents = sResult
end function

Pennimus
10-10-2007, 04:59 PM
Okay, thanks. And does this look right for actually using said function, as currently this just causes a redirect to the root of the domain that I put this script on...



dim page
page = file_get_contents("http://www.domain.com/page.html")
response.write(page)

H-SK33PY
06-21-2015, 08:21 AM
I might be wrong, but wouldn't this do it:


function file_get_contents(sURL)
dim xmlhttp, sResult
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET",sURL, false
xmlhttp.send sURL
sResult = xmlhttp.ResponseText
set xmlhttp = nothing
file_get_contents = sResult
end function

Hi i want this sample code too.
please tell me how can i use this with Unicode support like UTF-8
thanks a lot

Old Pedant
06-21-2015, 08:17 PM
That only works for url's. If you want a file that is NOT accessible by url, you must use the FileScriptingObject.

I THINK the way to get utf8 is to put
xmlhttp.ContentType = "text/utf8"
directly after the call to
xmlhttp.send

soluck90
07-12-2015, 03:08 AM
That only works for url's. If you want a file that is NOT accessible by url, you must use the FileScriptingObject.

I THINK the way to get utf8 is to put
xmlhttp.ContentType = "text/utf8"
directly after the call to
xmlhttp.send

I think you're right :).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum