public void Bind_Data() { string url = "http://www.baidu.cn"; System.Net.WebRequest req = System.Net.WebRequest.Create(url); System.Net.WebResponse res = req.GetResponse(); //获取页面字节大小 long bytes = res.ContentLength; Response.Write(bytes); //获取页面编码格式 string temp = res.ContentType; System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(temp, "charset=.*$"); temp = match.Value; string s = System.Text.RegularExpressions.Regex.Replace(temp, "charset=", "").Trim(); if (s == "") s = "utf-8"; Encoding code = Encoding.GetEncoding(s); //获取数据流 System.IO.Stream stream = res.GetResponseStream(); //读取字符 System.IO.StreamReader reader = new System.IO.StreamReader(stream, code); //存放 位置以及编码格式 System.IO.StreamWriter writer = new System.IO.StreamWriter(@"C:/Documents and Settings/Administrator/桌面/Demo/Web/index.html",false,code); string content = reader.ReadToEnd(); writer.Write(content); //关闭流 stream.Close(); writer.Close(); } public string GetHtml(string url) { WebRequest req; HttpWebResponse res; req = HttpWebRequest.Create(url); res = (HttpWebResponse)req.GetResponse(); Stream stream = res.GetResponseStream(); StreamReader sr = new StreamReader(stream, System.Text.Encoding.Default); System.IO.StreamWriter writer = new System.IO.StreamWriter(@"C:/Documents and Settings/Administrator/桌面/Demo/Web/index.html", false, Encoding.Default); string content = sr.ReadToEnd(); writer.Write(content); //string tempstr = sr.ReadToEnd(); stream.Close(); writer.Close(); return content; } private bool UrlExistsUsingSockets(string url) { if (url.StartsWith("http://")) url = url.Remove(0, "http://".Length); try { System.Net.IPHostEntry ipHost = System.Net.Dns.Resolve(url); return true; } catch (System.Net.Sockets.SocketException se) { return false; } }