2010年12月30日 星期四

下載一個網頁

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;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();
      }
   }

}

沒有留言: