首页 新闻 会员 周边 捐助

获取远程页面

0
[已关闭问题] 关闭于 2009-10-15 15:14
//获得页面文件
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();
}
}

        
南南的主页 南南 | 初学一级 | 园豆:4
提问于:2009-10-15 15:12
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册