//获得页面文件
private string RetrieveContent(string webPage)
{
if (webPage.Equals(" about:blank ")) return null;
if (!webPage.StartsWith(" http:// ") && !webPage.StartsWith(" https:// "))
{
webPage = " http:// " + webPage;
}
//Response.Write("<script>alert('" + webPage + "');</script>");
//到这里弹出是正常勒,
HttpWebResponse response = null;
StreamReader respStream = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webPage);
request.Timeout = 1000; //设置超时时间(ms)
request.Method = "GET";
request.UserAgent = " User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;) ";
request.Accept = " */* ";
request.KeepAlive = true;
request.Headers.Add(" Accept-Language ", " zh-cn,en-us;q=0.5 ");
response = (HttpWebResponse)request.GetResponse();
respStream = new StreamReader(response.GetResponseStream());
return respStream.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally
{
//关闭
response.Close();
respStream.Close();
}
}