你如何在asp.net中获得类似于php的get_file_contents的网页标记

时间:2022-01-03 23:50:11

I was trying to do something similar to the PHP command get_file_contents to get the market up a webpage, but it has to be in ASP.net. I wasnt sure if i could just open the webpage via file, and then just read the stream into another file.

我试图做一些类似于PHP命令get_file_contents的东西,以便在市场上推出一个网页,但它必须在ASP.net中。我不确定我是否可以通过文件打开网页,然后只需将流读入另一个文件。

One thought iw as thinking was: How to read an entire file to a string using C#? but i wasnt sure if that was the route i would be needing to go or if someone else knew something that would do what i wanted.

我们想到的一个想法是:如何使用C#将整个文件读取到字符串?但我不确定这是否是我需要去的路线,或者是否有人知道会做我想做的事情。

Looking for the answer to the following pseudocode:

寻找以下伪代码的答案:

$test = "www.google.com";
$string = get_file_contents($test);
$filePointer = fopen("sample.txt", "w+");
$filePointer.write($string);
fclose($filePointer);

2 个解决方案

#1


3  

string html;
using (var client = new WebClient())
{
    html = client.DownloadString("http://www.google.com");
}
Console.WriteLine(html);

#2


-1  

figured this might be what i was looking at: http://www.devprise.com/2006/07/14/c-method-to-mimic-php-file_get_contents/ Not sure though.

想到这可能就是我所看到的:http://www.devprise.com/2006/07/14/c-method-to-mimic-php-file_get_contents/但不确定。

#1


3  

string html;
using (var client = new WebClient())
{
    html = client.DownloadString("http://www.google.com");
}
Console.WriteLine(html);

#2


-1  

figured this might be what i was looking at: http://www.devprise.com/2006/07/14/c-method-to-mimic-php-file_get_contents/ Not sure though.

想到这可能就是我所看到的:http://www.devprise.com/2006/07/14/c-method-to-mimic-php-file_get_contents/但不确定。