[C#] 纯文本查看 复制代码
//打开
private void Form1_Load(object sender, EventArgs e)
{
HttpItem item = new HttpItem()
{
URL = "http://www.hb.xinhuanet.com/zhuanti/14one/cjxzpx/",//URL这里都是测试 必需项
Method = "get",//URL 可选项 默认为Get
//ResultCookieType = ResultCookieType.CookieCollection
};
//得到HTML代码
HttpResult result = http.GetHtml(item);
result = http.GetHtml(item);
//web_cookie = result.Cookie;
textBox3.Text = result.Html;
}
//进入到投票页面
private void button1_Click(object sender, EventArgs e)
{
HttpItem item = new HttpItem();
HttpResult result = http.GetHtml(item);
item = new HttpItem()
{
URL = "http://202.123.110.196/govvote/vote/admin/survey/securitySubmit.jsp?surveyID=2134",//URL这里都是测试URl 必需项
Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
//Encoding = Encoding.Default,
Method = "post",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = web_cookie,//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36",//用户的浏览器类型,版本,操作系统 可选项有默认值
Accept = "text/html, application/xhtml+xml, */*",// 可选项有默认值
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
Referer = "http://www.hb.xinhuanet.com/zhuanti/14one/cjxzpx/",//来源URL 可选项
//Allowautoredirect = true,//是否根据301跳转 可选项
//CerPath = "d:\\123.cer",//证书绝对路径 可选项不需要证书时可以不写这个参数
//Connectionlimit = 1024,//最大连接数 可选项 默认为1024
//Postdata = "C:\\PERKYSU_20121129150608_ScrubLog.txt",//Post数据 可选项GET时不需要写
//PostDataType = PostDataType.FilePath,//默认为传入String类型,也可以设置PostDataType.Byte传入Byte类型数据
//ProxyIp = "192.168.1.105:8015",//代理服务器ID 端口可以直接加到后面以:分开就行了 可选项 不需要代理 时可以不设置这三个参数
//ProxyPwd = "123456",//代理服务器密码 可选项
//ProxyUserName = "administrator",//代理服务器账户名 可选项
ResultType = ResultType.Byte,//返回数据类型,是Byte还是String
//PostdataByte = System.Text.Encoding.Default.GetBytes("test"),//如果PostDataType为Byte时要设置本属性的值
//CookieCollection = new System.Net.CookieCollection(),//可以直接传一个Cookie集合进来
Postdata = "selString=&askValue=&radioValue=&checkBoxValue=30166&selectValue=&radioRemarkValue=&checkRemarkValue=null&openfeatures2134=width%3D600%2Cheight%3D800%2Ctoolbar%3Dno%2Cmenubar%3Dno%2Cscrollbars%3Dyes%2Cresizable%3Dyes%2Clocation%3Dno%2Cstatus%3Dyes&4919_30166=30166&radioString=&checkBoxString=4919_30136%2C4919_30137%2C4919_30138%2C4919_30139%2C4919_30140%2C4919_30141%2C4919_30142%2C4919_30143%2C4919_30144%2C4919_30145%2C4919_30146%2C4919_30147%2C4919_30148%2C4919_30149%2C4919_30150%2C4919_30151%2C4919_30152%2C4919_30153%2C4919_30154%2C4919_30155%2C4919_30156%2C4919_30157%2C4919_30158%2C4919_30159%2C4919_30160%2C4919_30161%2C4919_30162%2C4919_30163%2C4919_30164%2C4919_30165%2C4919_30166%2C4919_30167%2C4919_30168%2C4919_30169%2C4919_30170%2C4919_30171%2C4919_30172%2C4919_30173%2C4919_30174%2C4919_30175%2C4919_30176%2C4919_30177%2C4919_30178%2C4919_30179%2C4919_30180%2C4919_30181%2C4919_30182%2C4919_30183%2C4919_30184%2C4919_30185%2C4919_30186%2C4919_30187%2C4919_30188%2C4919_30189%2C4919_30190%2C4919_30191%2C4919_30192%2C4919_30193%2C4919_30194%2C4919_30195%2C4919_30196%2C4919_30197%2C4919_30198%2C4919_30199%2C4919_30200%2C4919_30201%2C4919_30202%2C4919_30203%2C4919_30204%2C4919_30205%2C4919_30206%2C4919_30207%2C4919_30208%2C4919_30209%2C4919_30210%2C4919_30211%2C4919_30212%2C4919_30213%2C4919_30214%2C4919_30215%2C&selectString=&askString=&securitycode2134=1&votelimit2134=1&limittype2134=1"
};
//得到新的HTML代码
result = http.GetHtml(item);
textBox1.Text = result.Html;
//web_cookie = result.Cookie.Replace("path=/,", "").Replace("path=/", "");
textBox3.Text = web_cookie;
}
//获取验证码
private void button2_Click(object sender, EventArgs e)
{
HttpItem item = new HttpItem()
{
URL = "http://202.123.110.196/govvote/voteSecuCode",//URL 必需项
Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Referer = "http://202.123.110.196/govvote/vote/admin/survey/securitySubmit.jsp?surveyID=2134",
//Cookie = web_cookie,
//Encoding = Encoding.Default,
ResultType = ResultType.Byte,
ResultCookieType = ResultCookieType.CookieCollection,
};
//得到HTML代码
HttpResult result = http.GetHtml(item);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
//表示访问成功,具体的大家就参考HttpStatusCode类
}
//表示StatusCode的文字说明与描述
string statusCodeDescription = result.StatusDescription;
//把得到的Byte转成图片
Image img = byteArrayToImage(result.ResultByte);
pictureBox1.Image = img;
//得到新的HTML代码
result = http.GetHtml(item);
web_cookie = result.Cookie.Replace("path=/,", "").Replace("path=/", "");
textBox3.Text = web_cookie;
}
private Image byteArrayToImage(byte[] Bytes)
{
MemoryStream ms = new MemoryStream(Bytes);
Image outputImg = Image.FromStream(ms);
return outputImg;
}
//提交
private void button3_Click(object sender, EventArgs e)
{
HttpItem item = new HttpItem();
HttpResult result = http.GetHtml(item);
item = new HttpItem()
{
URL = "http://202.123.110.196/govvote/vote/admin/survey/surveySubmit.jsp",//URL这里都是测试URl 必需项
Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
//Encoding = Encoding.Default,
Method = "post",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = web_cookie,
UserAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36",//用户的浏览器类型,版本,操作系统 可选项有默认值
Accept = "text/html, application/xhtml+xml, */*",// 可选项有默认值
ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
Referer = "http://202.123.110.196/govvote/vote/admin/survey/securitySubmit.jsp?surveyID=2134",//来源URL 可选项
Postdata = "scode2134="+ textBox2.Text.ToString().Trim() +"&radioString=&checkBoxString=4919_30136%2C4919_30137%2C4919_30138%2C4919_30139%2C4919_30140%2C4919_30141%2C4919_30142%2C4919_30143%2C4919_30144%2C4919_30145%2C4919_30146%2C4919_30147%2C4919_30148%2C4919_30149%2C4919_30150%2C4919_30151%2C4919_30152%2C4919_30153%2C4919_30154%2C4919_30155%2C4919_30156%2C4919_30157%2C4919_30158%2C4919_30159%2C4919_30160%2C4919_30161%2C4919_30162%2C4919_30163%2C4919_30164%2C4919_30165%2C4919_30166%2C4919_30167%2C4919_30168%2C4919_30169%2C4919_30170%2C4919_30171%2C4919_30172%2C4919_30173%2C4919_30174%2C4919_30175%2C4919_30176%2C4919_30177%2C4919_30178%2C4919_30179%2C4919_30180%2C4919_30181%2C4919_30182%2C4919_30183%2C4919_30184%2C4919_30185%2C4919_30186%2C4919_30187%2C4919_30188%2C4919_30189%2C4919_30190%2C4919_30191%2C4919_30192%2C4919_30193%2C4919_30194%2C4919_30195%2C4919_30196%2C4919_30197%2C4919_30198%2C4919_30199%2C4919_30200%2C4919_30201%2C4919_30202%2C4919_30203%2C4919_30204%2C4919_30205%2C4919_30206%2C4919_30207%2C4919_30208%2C4919_30209%2C4919_30210%2C4919_30211%2C4919_30212%2C4919_30213%2C4919_30214%2C4919_30215%2C&radioValue=&checkBoxValue=30166&surveyID=2134&view=&askString=&askValue=&selectString=&selectValue=&radioRemarkValue=&checkRemarkValue=null&enp_username=%E5%8C%BF%E5%90%8D%E7%94%A8%E6%88%B7&enp_usermail=%E5%8C%BF%E5%90%8D%E9%82%AE%E4%BB%B6&enp_country=&enp_province=&enp_sex=2&enp_degree=&enp_occupation=&enp_animals=&enp_star=&enp_blood=&enp_belief=&enp_idcard=&enp_phone=&enp_address=&enp_marriage=&votelimit2134=1&limittype2134=1&securitycode2134=1"
};
//得到新的HTML代码
result = http.GetHtml(item);
textBox1.Text = result.Html;
}