模拟ASPX页面POST相关参数
来源:互联网 发布:舞蹈服装大全淘宝网 编辑:程序博客网 时间:2024/05/06 08:22
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
namespace WSSERVER
{
public partial class Test : Form
{
public Test()
{
InitializeComponent();
}
BZDM dm2 = new BZDM();
DM dm = new DM();
private void button1_Click(object sender, EventArgs e)
{
//getYL();
// getYL();
string url = "http://61.191.22.155/TYFW/InfoQuery/ZhaBasec.aspx";
StringBuilder sb=new StringBuilder();
string mes = getHTMLUTF(url);
Regex regex = new Regex("(?<=<input type=/"hidden/" name=/"__VIEWSTATE/" id=/"__VIEWSTATE/" value=/")[//s//S]*?(?=/" />)", RegexOptions.IgnoreCase);
MatchCollection matchs = regex.Matches(mes);
Regex regex2 = new Regex("(?<=<input type=/"hidden/" name=/"__EVENTVALIDATION/" id=/"__EVENTVALIDATION/" value=/")[//s//S]*?(?=/" />)", RegexOptions.IgnoreCase);
MatchCollection matchs2 = regex2.Matches(mes);
//DataSet ds=dm.getsql("select * from FH_SWZ_D WHERE TIME>TO_DATE('" + System.DateTime.Now.ToShortDateString() + "','YYYY-MM-dd') and NAME='"+space+"'");
sb.Append("__VIEWSTATE=" + convertURL(matchs[0].Value));
sb.Append("&__EVENTVALIDATION=" + convertURL(matchs2[0].Value));
sb.Append("&" + convertURL("DTYearMonthDayHour1$DDLYear") + "=" + System.DateTime.Now.Year);
sb.Append("&" + convertURL("DTYearMonthDayHour1$DDLMonth") + "=" + System.DateTime.Now.Month);
sb.Append("&" + convertURL("DTYearMonthDayHour1$DDLDay") + "=" + System.DateTime.Now.Day);
sb.Append("&" + convertURL( "DTYearMonthDayHour1$DDLHour") + "=07");
sb.Append("&" + convertURL("DTYearMonthDayHour2$DDLYear") + "=" + System.DateTime.Now.Year);
sb.Append("&" + convertURL("DTYearMonthDayHour2$DDLMonth") + "=" + System.DateTime.Now.Month);
sb.Append("&" + convertURL("DTYearMonthDayHour2$DDLDay") + "=" + System.DateTime.Now.Day);
sb.Append("&" + convertURL("DTYearMonthDayHour2$DDLHour") + "=09");
sb.Append("&" + "Rads" + "=on");
sb.Append("&" + "lbxStation" + "=50402500");
sb.Append("&" + "lbxReturnList" + "=0");
sb.Append("&" + "TbxList" + "=50402500,");
sb.Append("&" + "Button1" + "=" + convertURL("查询"));
string postparam = sb.ToString();
mes = GetPage(url, postparam);
Regex regex3 = new Regex("(?<=<tr class=Table112_tr1)[//s//S]*?(?=tr>)", RegexOptions.IgnoreCase);
MatchCollection matchs3 = regex3.Matches(mes);
for (int i = 0; i < matchs3.Count; i++)
{
string TRSTR = matchs3[i].Value;
Regex regex5 = new Regex(@"(?<=<td)[/s/S]*?(?= </td>)", RegexOptions.IgnoreCase);
MatchCollection matchs5 = regex5.Matches(TRSTR);
string tdstr = matchs5[0].Value;
string name = tdstr.Split('>')[1];
tdstr = matchs5[2].Value;
string sw1 = tdstr.Split('>')[1];
tdstr = matchs5[4].Value;
string sw2 = tdstr.Split('>')[1];
MessageBox.Show(name + ":" + sw1 + "====" + sw2);
}
}
public string convertURL(string tmp)
{
return HttpUtility.UrlEncode(tmp);
}
public string getHTMLGB2312(string URL)
{
string aa = "";
WebRequest req = WebRequest.Create(URL);
try
{
WebResponse result = req.GetResponse();
//得到的流是网页内容
Stream ReceiveStream = result.GetResponseStream();
StreamReader readerOfStream = new StreamReader(ReceiveStream,
System.Text.Encoding.GetEncoding("GB2312"));
aa = readerOfStream.ReadToEnd();
ReceiveStream.Close();
}
catch (Exception)
{
}
return aa;
}
public string GetPage(string posturl, string postData)
{
Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
Encoding encoding = System.Text.Encoding.GetEncoding("UTF-8");
byte[] data = encoding.GetBytes(postData);
// 准备请求...
try
{
// 设置参数
request = WebRequest.Create(posturl) as HttpWebRequest;
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
outstream = request.GetRequestStream();
outstream.Write(data, 0, data.Length);
outstream.Close();
//发送请求并获取相应回应数据
response = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回结果网页(html)代码
string content = sr.ReadToEnd();
string err = string.Empty;
return content;
}
catch (Exception ex)
{
string err = ex.Message;
return string.Empty;
}
}
public string getHTMLUTF(string URL)
{
string aa = "";
WebRequest req = WebRequest.Create(URL);
try
{
WebResponse result = req.GetResponse();
//得到的流是网页内容
Stream ReceiveStream = result.GetResponseStream();
StreamReader readerOfStream = new StreamReader(ReceiveStream,
System.Text.Encoding.GetEncoding("UTF-8"));
aa = readerOfStream.ReadToEnd();
ReceiveStream.Close();
}
catch (Exception)
{
}
return aa;
}
public string getHTML(string URL)
{
string aa = "";
WebRequest req = WebRequest.Create(URL);
try
{
WebResponse result = req.GetResponse();
//得到的流是网页内容
Stream ReceiveStream = result.GetResponseStream();
StreamReader readerOfStream = new StreamReader(ReceiveStream,
System.Text.Encoding.GetEncoding("GB2312"));
aa = readerOfStream.ReadToEnd();
ReceiveStream.Close();
}
catch (Exception)
{
}
return aa;
}
}
}
- 模拟ASPX页面POST相关参数
- 在aspx页面向iframe中post参数
- 关于post一个aspx页面
- Aspx页面模拟WebService功能
- aspx.cs 模拟post发起请求
- restClient模拟post添加参数
- perl post 请求相关参数
- aspx页面接收不到post的文件流
- 如何使用html页面和aspx页面接收参数
- .aspx页面传值到.htm页面的接受参数值写法
- PHP CURL模拟POST传递参数
- 关于Fiddler模拟POST参数问题
- fiddler 模拟 post请求添加参数
- CURL模拟表单post提交及相关常用参数的使用(包括提交表单同时上传文件)
- CURL模拟表单post提交及相关常用参数的使用(包括提交表单同时上传文件)
- HttpClient 4.1.3 初学篇---使用Get和Post模拟登录简单页面(分别带参数)
- 使用Server.Transfer在两个ASPX页面间传递参数
- 使用Server.Transfer在两个ASPX页面间传递参数
- Visual Studio 2008 Team Suite Edition的破解方法!
- 8个可视化搜索引擎网站
- 找回误删并清除了回收站的文档
- 爱上对方法
- 爱上对方法
- 模拟ASPX页面POST相关参数
- python 2.6 multiprocessing 的使用
- 0620
- 使用jQuery方便的统计Repeater列的总和
- 字符串的截取
- php提取HTML中字符
- 快两年了, EasyJWeb 1.3 Beta 公布
- 数独也叫81宫源码即讲解
- 数独也叫81宫源码即讲解