1. 程式人生 > >[C#]一個簡單的獲取網頁原始碼的函式

[C#]一個簡單的獲取網頁原始碼的函式

獲取網頁原始碼,顯示在richTextBoxWeb中:

   private void Show_Web()
        {
            // 獲取網頁原始碼
            string url = "www.XXXXXXXXX.com";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            Stream resStream = response.GetResponseStream();
            StreamReader sr = new StreamReader(resStream);
            string strfile = sr.ReadToEnd();

            richTextBoxWeb.Text = url + "\n";
            richTextBoxWeb.Text += strfile;
        }