Ccav's "I want to go to the Spring Festival Gala" sets up the voting function and selects the popular one. I wrote a simple ticket collector.
Leave work first. Write the code when it is free.
From yesterday.
Like this vote page: http://cctv.cntv.cn/woyaoshangchunwan/vote/02/index.shtml
Try it out and capture packets. The data packet of post is as follows:
Encoding = gb2312 & _ charset _ = UTF-8 & returl = http % 3A % 2f % 2fapp1.vote.cntv.cn % 2fviewresult. JSP % 3 fvoteid % 3d3434 & formhash = 69256b23 & voteid = 3434 & type = HTML & items_6351 = 36451 & 63 = % E7 % 8e % 8B % E5 % B0 % 8f % E4 % ba % 8C & 65 = ID card No. & submitbtn = % E6 % 8A % 95% E7 % a5 % A8
The submitted processing page is http://app2.vote.cntv.cn/makeVoteAction.do
A total of program IDs, encoded names, and ID card numbers are submitted. Then, use httpwebrequest to simulate sending data.
ID card numbers can be generated randomly. I read them from an Excel worksheet.
The main code is as follows:
/// <Summary> <br/> // handles the Click Event of the btnvote control. <br/> /// </Summary> <br/> /// <Param name = "sender"> the source of the event. </param> <br/> // <Param name = "E"> the <see CREF = "system. eventargs "/> instance containing the event data. </param> <br/> private void btnvote_click (Object sender, eventargs E) <br/>{< br/> try <br/> {<br/> int interval = convert.toint32(this.txt interva L. text. trim (); <br/> // read data from an Excel table <br/> string filepath = this.txt filename. text. trim (); <br/> oledbconnection conn = new oledbconnection ("provider = Microsoft. jet. oledb.4.0; Data Source = "+ filepath +"; extended properties = Excel 8.0 "); <br/> Conn. open (); <br/> string strsql = "select * from [employee table $]"; <br/> oledbcommand cmd = new oledbcommand (strsql, Conn ); <br/> oledbdatareader ODR = cmd. execut Ereader (); <br/> int I = 0; <br/> while (ODR. read () <br/>{< br/> // create an httpwebrequest <br/> httpwebrequest myhttpwebrequest = (httpwebrequest?webrequest.create(this.txt action. text); </P> <p> string postdata = @ "encoding = gb2312 & _ charset _ = UTF-8 & returl = http % 3A % 2f % 2fapp1.vote.cntv.cn % 2fviewresult. JSP % 3 fvoteid % 3d3422 & formhash = 69256b23 & voteid = 3422 & type = HTML & session ID = program id & 10 = "+ Uri. escapedatastring (ODR ["name"]. Tostring () + "& 11 =" + ODR ["ID card number"]. tostring () + "& submitbtn = % E6 % 8A % 95% E7 % a5 % A8 "; </P> <p> // the content to be sent contains Chinese characters and spaces </P> <p> asciiencoding encoding = new asciiencoding (); <br/> byte [] byte1 = encoding. getbytes (postdata); // The data to be uploaded after the final encoding <br/> // setthecontenttypeofthedatabeingposted. <br/> myhttpwebrequest. contenttype = "application/X-WWW-form-urlencoded"; <br/> myhttpwebrequest. method = "Post"; // post upload method <br/> // Setthecontentlengthofthestringbeingposted. <br/> // myhttpwebrequest. referer = @ "http://cctv.cntv.cn/woyaoshangchunwan/vote/02/index.shtml"; <br/> myhttpwebrequest. contentlength = byte1.length; </P> <p> stream newstream = myhttpwebrequest. getrequeststream (); <br/> newstream. write (byte1, 0, byte1.length); <br/> // Add this statement to release the resource; otherwise, the execution gets stuck twice. <br/> myhttpwebrequest. abort (); <br/> newstream. close (); </P> <p> // get The new response <br/> // httpwebresponse response = myhttpwebrequest. getresponse () as httpwebresponse; <br/> // stream responsestream = response. getresponsestream (); <br/> // streamreader reader = new system. io. streamreader (responsestream); <br/> // string srcstring = reader. readtoend (); <br/> // this.txt responseinfo. TEXT = srcstring; </P> <p> thread. sleep (interval); <br/> I ++; <br/>}< br/> this.txt re Eclipseinfo. Text = "processed. Voting in total "+ I. tostring () + "times"; <br/> ODR. close (); <br/> cmd. dispose (); <br/> Conn. close (); <br/> Conn. dispose (); </P> <p >}< br/> catch (exception ex) <br/>{< br/> MessageBox. show ("error message:" + ex. message); <br/>}</P> <p>}
Note that if you want to send data in Chinese, you need URI. escapedatastring () to run it. If the program continues to improve, you can add the voting program id and add thread processing.
There is no verification code for this vote, and there are a lot of votes.