C#抓取网页代码存在字符串里
public static string GetWebPageAsString(string url) {
HttpWebRequest httpWebRequest =(HttpWebRequest)WebRequest.Create(url);
// you may need these next two lines to prevent a .net bug
// System.IO.IOException : Unable to read data from the transport connection: The connection was closed.
// see http://support.microsoft.com/default.aspx?scid=kb;EN-US;915599
httpWebRequest.KeepAlive = false;
httpWebRequest.ProtocolVersion = HttpVersion.Version10;
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream stream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(stream, Encoding.ASCII);
return streamReader.ReadToEnd();
}
