自动投票器的原理及设计思路 http://blog.csdn.net/lkfstar/archive/2008/01/12/2039070.aspx

来源:互联网 发布:xp电脑mac地址怎么查 编辑:程序博客网 时间:2024/05/20 16:34

自动投票器的原理及设计思路
___________________________
罗坤凡 2008-01-12

    网络投票和平时浏览网页、登陆邮箱一样,都是客户端和网站服务器之间的通讯过程。客户端发出信息请求,服务器端收到信息后根据后台程序作出相应的反馈,客户端收到反馈信息后再显示出来。

    手工投票时,客户端电脑打开IE,点击投票按钮,IE就会发送一定的信息到服务器,服务器收到信息后进行处理,再将结果反馈回客户端的IE,用户就会在IE中看到投票是否成功的信息。

    自动投票器的原理就是循环模拟手动投票的过程,大致分为以下几个步骤:

    1、打开IE手动投票,使用专门工具获取投票时IE往服务器提交的信息。

    2、分析信息得到提交的网址、提交的数据等。

    3、编程模拟手动投票往服务器发送投票信息,循环发送信息就可以达到快速投票。

    获取信息和分析信息在Outdovote通用网络自动投票器的说明文件里有,这里就不再说了,下面讲讲Microsoft Visual Studio 2005 C#如何编程模拟手工投票发送信息。

假如投票时获取的数据如下:

POST /generalvote/webvote/savevote.asp HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://www.outdosz.cn/generalvote/webvote/vote.asp
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
Proxy-Connection: Keep-Alive
Content-Length: 42
Host: www.outdosz.cn
Pragma: no-cache
Cookie: ASPSESSIONIDAACTDRCR=CHAMMJLDMCKFLLLOIADDFPGK; ASPSESSIONIDAACQASDR=PHILKNLDIPNPCOCDMAFANJFB; ASPSESSIONIDCACTCTBR=MJAAAGMDBFKLAFOGKDDCKEED

citygroup=%C7%E0%B5%BA&submit=%CC%E1%BD%BB

那么如何用编程来发送这样的数据呢,C#有个WebClient类,这个类非常好用,我们就用它来实现发送投票信息。

WebClient类可以自定义HTTP Headers属性(设置HTTP头信息),使用UploadData函数就可以POST数据到服务器,关于WebClient类的更多信息,请参考MSDN。

C#代码如下:

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.outdosz.cn/generalvote/webvote/vote.asp");
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.outdosz.cn/generalvote/webvote/savevote.asp", "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;

将以上代码封装在一个函数中,然后做个循环就可以实现连续投票了。

 


免费通用网络自动投票器
  WWW.OUTDOVOTE.CN 

 
原创粉丝点击