62,269
社区成员
发帖
与我相关
我的任务
分享 /// <summary>
/// 通过URL执行WEN后获取页面内容
/// </summary>
/// <param name="url"></param>
public static string ExecutePage(string urlstr)
{
string content = "";
if (urlstr.IndexOf("http://", StringComparison.OrdinalIgnoreCase) != 0 && urlstr.IndexOf("/") == 0)
{
urlstr = "http://" + HttpContext.Current.Request.Url.Host + urlstr;
}
else if (urlstr.IndexOf("http://", StringComparison.OrdinalIgnoreCase) != 0)
{
urlstr = "http://" + urlstr;
}
System.Net.WebResponse wResp = null;
System.IO.Stream respStream = null;
System.IO.StreamReader reader = null;
try
{
Uri url = new Uri(urlstr);
System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);
wResp = wReq.GetResponse();
respStream = wResp.GetResponseStream();
reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8"));
content = reader.ReadToEnd();
}
catch (System.Net.WebException ex)
{
//return ex.Source + ":" + urlstr;
throw;
}
finally
{
if (reader!= null)
reader.Close();
if (respStream != null)
respStream.Close();
if (wResp != null)
wResp.Close();
}
return content;
} protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string artNO = this.Request["articleNO"];
if (artNO == null || artNO == "")
{
return;
//这里我就退出去了,不知这样可以吗?
}
modelart = bllart.GetModel(artNO);
if (modelart == null)
{
return;
}
}
}