[C#]一個簡單的獲取網頁原始碼的函式
阿新 • • 發佈:2018-12-23
獲取網頁原始碼,顯示在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; }