2011-01-21 19 views

回答

3

我不知道你所說的「獲取內容」的意思,但在這裏是從任何網站下載HTML代碼的函數:

public string Download(string url, Encoding encoding) 
{ 
    string content = string.Empty; 
    using (WebClient client = new WebClient { Encoding=encoding }) 
    { 
     Stream data = client.OpenRead(url); 
     using (StreamReader sr = new StreamReader(data, encoding)) 
     { 
      content = sr.ReadToEnd(); 
     } 
     data.Close(); 
    } 
    return content; 
} 
4

你可以使用一個WebClient

using (var client = new WebClient()) 
{ 
    string result = client.DownloadString("http://www.google.com"); 
} 
相關問題