日期:2014-05-17 浏览次数:20585 次
public string GetHtml(string url, Encoding ec)
{
try
{
WebRequest request = WebRequest.Create(url);//实例化WebRequest对象
WebResponse response = request.GetResponse();//创建WebResponse对象
Stream datastream = response.GetResponseStream();//创建流对象
StreamReader reader = new StreamReader(datastream, ec);
string str = reader.ReadToEnd();
response.Close();
reader.Close();
datastream.Close();
return str;
}
catch (Exception e)
{ return ""; }
}
//调用
//string str = GetHtml("http://www.beyland.com/beyland/beyland/index/getip001.asp", Encoding.Default);