复制代码 代码如下:
public static string GetSourceTextByUrl(string url)
{
WebRequest request = WebRequest.Create(url);
request.Timeout = 200000;//20秒超时
WebResponse response = request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream);
string tempstr = sr.ReadToEnd();
Regex r1 = new Regex("<input type=\"hidden\" name=\"__EVENTTARGET\".*/>", RegexOptions.IgnoreCase);
Regex r2 = new Regex("<input type=\"hidden\" name=\"__EVENTARGUMENT\".*/>", RegexOptions.IgnoreCase);
Regex r3 = new Regex("<input type=\"hidden\" name=\"__VIEWSTATE\".*/>", RegexOptions.IgnoreCase);
//过滤<form>代码
Regex r4 = new Regex("<form name=\"aspnetForm\".*id=\"aspnetForm\">", RegexOptions.IgnoreCase);
Regex r5 = new Regex("</form>");
tempstr = r1.Replace(tempstr, "");
tempstr = r2.Replace(tempstr, "");
tempstr = r3.Replace(tempstr, "");
tempstr = r4.Replace(tempstr, "");
tempstr = r5.Replace(tempstr, "");
return tempstr;
}
public static string GetSourceTextByUrl(string url)
{
WebRequest request = WebRequest.Create(url);
request.Timeout = 200000;//20秒超时
WebResponse response = request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream);
string tempstr = sr.ReadToEnd();
Regex r1 = new Regex("<input type=\"hidden\" name=\"__EVENTTARGET\".*/>", RegexOptions.IgnoreCase);
Regex r2 = new Regex("<input type=\"hidden\" name=\"__EVENTARGUMENT\".*/>", RegexOptions.IgnoreCase);
Regex r3 = new Regex("<input type=\"hidden\" name=\"__VIEWSTATE\".*/>", RegexOptions.IgnoreCase);
//过滤<form>代码
Regex r4 = new Regex("<form name=\"aspnetForm\".*id=\"aspnetForm\">", RegexOptions.IgnoreCase);
Regex r5 = new Regex("</form>");
tempstr = r1.Replace(tempstr, "");
tempstr = r2.Replace(tempstr, "");
tempstr = r3.Replace(tempstr, "");
tempstr = r4.Replace(tempstr, "");
tempstr = r5.Replace(tempstr, "");
return tempstr;
}
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com
暂无“asp.net 生成静态时的过滤viewstate的实现方法”评论...