WebClient位於System.Net命名空間下,通過這個類可以方便的創建Http請求並獲取返回內容。
string uri = "http://hovertree.top/"; WebClient wc = new WebClient(); Console.WriteLine("Sending an HTTP GET request to " + uri); byte[] bResponse = wc.DownloadData(uri); string strResponse = Encoding.ASCII.GetString(bResponse); Console.WriteLine("HTTP response is: "); Console.WriteLine(strResponse); // 何問起
string uri = "http://hovertree.net"; WebClient wc = new WebClient(); Console.WriteLine("Sending an HTTP GET request to " + uri); Stream st = wc.OpenRead(uri); StreamReader sr = new StreamReader(st); string res = sr.ReadToEnd(); sr.Close(); st.Close(); Console.WriteLine("HTTP Response is "); Console.WriteLine(res); // 何問起
推薦:http://www.cnblogs.com/roucheng/p/3521864.html