一种方法 string url = "http://www.xxx.net/index.aspx"; string text; System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url); // Get the response instance. System.Net.WebResponse wResp =wReq.GetResponse(); // Read an HTTP-specific property //if (wResp.GetType() ==HttpWebResponse) //{ //DateTime updated =((System.Net.HttpWebResponse)wResp).LastModified; //} // Get the response stream. System.IO.Stream respStream = wResp.GetResponseStream(); // Dim reader As StreamReader = New StreamReader(respStream) System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312")); text=reader.ReadToEnd(); // Create an instance of StreamWriter to write text to a file. // The using statement also closes the StreamWriter. string path = System.Web.HttpContext.Current.Server.MapPath("default.htm"); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path,false,System.Text.Encoding.UTF8)) { // Add some text to the file. if(text.Trim() !="") { sw.Write(text); } }第二种方法 编写一个模板,替换里面的内容。
string url = "http://www.xxx.net/index.aspx";
string text;
System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
// Get the response instance.
System.Net.WebResponse wResp =wReq.GetResponse();
// Read an HTTP-specific property
//if (wResp.GetType() ==HttpWebResponse)
//{
//DateTime updated =((System.Net.HttpWebResponse)wResp).LastModified;
//}
// Get the response stream.
System.IO.Stream respStream = wResp.GetResponseStream();
// Dim reader As StreamReader = New StreamReader(respStream)
System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
text=reader.ReadToEnd();
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
string path = System.Web.HttpContext.Current.Server.MapPath("default.htm");
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path,false,System.Text.Encoding.UTF8))
{
// Add some text to the file.
if(text.Trim() !="")
{
sw.Write(text);
}
}第二种方法
编写一个模板,替换里面的内容。