- 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();
- }
- //该片段来自于http://www.codesnippet.cn/detail/090620133951.html
来源: http://www.codesnippet.cn/detail/090620133951.html