Save any web page
We can save the web page using following simple code
using System.Net;
using System.IO;
public class SaveWebPage {
public static void Main() {
String MyPage = "http://www.DotnetSpider.com/snathanm.html";
HttpWebRequest MyHttpWebRequest = (HttpWebRequest)WebRequest.Create(MyPage);
HttpWebResponse MyHttpWebResponse =(HttpWebResponse) MyHttpWebRequest.GetResponse();
Stream MyDataStream = MyHttpWebResponse.GetResponseStream();
StreamReader MyStreamReader = new StreamReader(MyDataStream);
String MyDataString = MyStreamReader.ReadToEnd();
Console.WriteLine(MyDataString);
}
}
Code Explanation
1. Create the instance of HttpWebRequest using your web page.
2. Create the instance of HttpWebResponse by geting response
3. Read the response using stramreader and use it.
4. convert it into string.
5. If you need save the stream into a file
By
Nathan
