Get the source of some website from asp.net code

前端 未结 3 1390
感情败类
感情败类 2020-12-30 17:38

Is there any way that I could get the source of a website (as a string preferably), let\'s say www.google.com, from some c# code inside code behind of asp.net website?

3条回答
  •  旧巷少年郎
    2020-12-30 18:10

    Assuming you want to retrieve the html:

    class Program
    {
        static void Main(string[] args)
        {
            using (WebClient client = new WebClient())
            using (Stream stream = client.OpenRead("http://www.google.com"))
            using (StreamReader reader = new StreamReader(stream))
            {
                Console.WriteLine(reader.ReadToEnd());
            }
        }
    }
    

提交回复
热议问题