Boolean postData(string voteDATA)
{
WebClient myWebClient = new WebClient();//申明并创建WebClient实例myWebClient
byte[] byteArray;//申明存储提交数据的变量
byte[] responseArray;//申明存储接收数据的变量
//设置HTTP头信息,并非所以的信息都需要设置,以下这些信息足够了
myWebClient.Headers.Add("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
myWebClient.Headers.Add("Referer", "http://www.deyang.gov.cn/dyweb/");
myWebClient.Headers.Add("Accept-Language", "zh-cn");
myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
myWebClient.Headers.Add("Accept-Encoding", "gzip, deflate");
byteArray = Encoding.Default.GetBytes(voteDATA);//将提交的数据转化为byte数组
try
{
responseArray = myWebClient.UploadData("http://www.deyang.gov.cn/dyweb/inquiry.asp?id=4", "POST", byteArray);//提交投票信息,并获取返回的数据
}
catch (Exception exPOST)
{
//errorMessage = "/nPOST方式投票时出现错误,错误信息为:" + exPOST.Message;
myWebClient.Dispose();//释放myWebClient所占用的资源
return false;//提示错误信息并返回。
}
myWebClient.Dispose();//释放myWebClient所占用的资源
//outputMessage = "/n接收的正文信息:/n";
// outputMessage = outputMessage + Encoding.Default.GetString(responseArray);
return true;
}
protected void Button1_Click(object sender, EventArgs e)
{
string voteDATA = "id=4&toupiao=0&inquiry=14&Submit2=+%CC%E1+%BD%BB+";
int i;
for (i = 0; i < 1000; i++)
{
postData(voteDATA);
}
Response.Write("<script>alert('自动投票结束!');</script>");
}