110,538
社区成员
发帖
与我相关
我的任务
分享
protected string getHtml(string url)
{
string html = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Accept = "*/*";
HttpWebResponse response = null;
Stream stream = null;
StreamReader reader = null;
try
{
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
reader = new StreamReader(stream, Encoding.Default);
html = reader.ReadToEnd();//.Replace("\r\n", "");
}
catch (Exception excpt)
{
MessageBox.Show(excpt.Message);
}
finally
{
if (reader != null)
{
reader.Close();
reader.Dispose();
}
if (stream != null)
{
stream.Close();
stream.Dispose();
}
if (response != null)
{
response.Close();
}
}
return html;
}