本文实例讲述了C#下载网页并在控制台输出的方法。分享给大家供大家参考。具体实现方法如下:
using System;using System.Net;using System.Text;using System.IO;namespace Test {class GetWebPage { public static void Main(string[] args) { for(int i=0;ilt;args.Length;i++) { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(args[i]); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream stream = httpWebResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(stream, Encoding.ASCII); Console.WriteLine(streamReader.ReadToEnd()); } Console.Read(); } }}
希望本文所述对大家的C#程序设计有所帮助。
新闻热点
疑难解答