C # Auto-collect gold function to a website

Source: Internet
Author: User

Demand analysis


The small wood bug is my student time frequently browses the forum, this station mainly to the academic discussion mainly, at that time on this above still has learned many thesis aspect posture.

Each landing forum can not forget the above "daily red envelope" function, each person once a day to receive gold coins opportunity, gold coins like to do a lot of things. Gradually, I grew up, although still often landed on the forum to see, but the "daily red envelope" function due to the steps of "complex" (need to click a few mouse to receive), and gold is not much to me, and my gold has never increased. Until the day before yesterday, I need gold coins, I only know when the coin to time side hate less. If God could give me another chance ... Therefore, I made an important decision to regain the "daily red envelope" function, and, this time I am a full-scale three-dimensional high-force lattice way to get red envelopes. Lying trough, off the topic, is this a demand analysis?


Overview design


No.


Detailed design


No.

Well, I really can't pretend to go, the following into the topic.


Business


I do not want to pass the "open Web page, enter the forum, the daily red envelopes, choose the type, submit" This series of steps to get gold, I want to click on a button to get gold, I want to be very convenient to receive gold, I want a lot of beauty ... , and it's irrelevant.

Club? By clicking the button, send the HTTP request way, a button to collect gold?! Yes, it is so cool, this acid is authentic ...

So, how to send HTTP requests, need to use courier ... , well, no, it's okay.

is the Red Envelope Collection page, the URL is http://emuch.net/bbs/memcp.php?action=getcredit&uid=xxxxxx:


Then the chrome right-click Review element, we found the legendary form:


OK, now let's click on the "Collect Red envelopes" button to see what happens to the club? So I chose the "Daily adventure", I wrote down a sentence for myself "Duang ...", I poked the "Collect red envelope" button.

Wait a minute....

Don't forget to open Chrome's web monitoring window before the Poke button, we have to monitor what's going on.


Isn't that the legendary post request? Clearly, this is the HTTP request to send the data, you are satisfied with it (week star tone)! the elder brother smiled proudly, because elder brother's analysis completes, next elder brother wants to use C # to imitate this process, elder brother wants to imitate it, imitate her, touch her, touch ...

OK, let's have a nice simulation.

Wait a minute...

How to simulate? Let me organize my thoughts, organize the language, the steps are as follows:

1. I want a lot of beauties ... Lying trough and irrelevant;

2. Send a GET request, URL is http://emuch.net/bbs/memcp.php?action=getcredit&uid=xxxxxx, get the Red Envelopes page. Why go to the Red envelopes page? Why not just send the above-mentioned post request directly to receive the red envelopes? Because there is a hidden field input:formhash in the form form, it can be found in the image above. So the form submission is needed for this formhash data, so ... I get the Formhash data from this page first, so I get this formhash with the following code .

String des = "<input type=\" hidden\ "name=\" formhash\ "value=\"; int index = HTML. IndexOf (DES); string formhash = html. Substring (index + des). Length, 8);
so we were happy to get to the Formhash.

What's that uid=xxxxxx? Yes, just. Is. Use. Households. Id.. , how does this get it? I'll tell you later.

3. Construct the post-collect gold request and send it. This step is very simple, the parameters in the form of the honest construction, and then the POST request sent, the gold coins will be handed.


Well, that's the end of it.

Wait a minute...

What do you think it's missing? What about cookies? What about the uid=xxxxxx up there? Where's the beauty? All right, it's down there.

What is 4.cookie? Is someone else's server to determine whether you login credentials, did not log on to rob Gold? Do you think you're crazy about gold? So, we have to let the server know, I am a landed person, the cookie to others just. But... To get a cookie, I have to send a login request, and there is a login verification code, this job can not dry! At this point, a beautiful woman's head appeared in my mind, she said, you go to the chrome settings inside to see. So I found this in the Chrome settings:


Hum, a bit of meaning. This means that the logged-in cookie is saved, and I read it without a cookie? So I found this:


Open it:


It's all garbled, but I see a few of the characters of SQLite appear in there, this is the legendary SQLite database? So I took a try to buy a course of treatment .... No, so I set foot on the SQLite database reading path. Found these two things on the internet and imported them into the project:


DataTable dt = Sqllitehelper.executesql (@ "SELECT * from the cookie where Host_key like '%emuch% '");    public class Sqllitehelper    {public        static string connectionString = @ "Data source=c:\users\xxxxxxxx\appdata\ Local\google\chrome\user data\default\cookies ";        public static DataTable ExecuteSQL (String sql)        {            using (var conn = new System.Data.SQLite.SQLiteConnection ( connectionString))            {                Conn. Open ();                var cmd = conn. CreateCommand ();                Cmd.commandtext = SQL;                using (var reader = cmd. ExecuteReader ())                {                    var datatable = new DataTable ();                    Datatable.load (reader);                    Conn. Close ();                    return dataTable;}}}    

through the above code, I easily get the cookie data, as well as the above mentioned uid=xxxxxx, do not believe you see:


So, I am happy to take the cookie and post data to a button to collect coins:

RQ = new Httprequestparameter ();            String uid = "";            Httpcookietype cookies = new Httpcookietype ();            cookiecollection cc = new Cookiecollection (); foreach (DataRow dr in Dt.                Rows) {Cookie cookie = new Cookie (); Cookies. Name = dr["Name"].                ToString (); Cookies. Value = dr["value"]. ToString (). Replace (",", "%2c"),//cookie value in the presence of a comma will be an error, do not know why? Change the comma to%2c and the cookie is OK. Domain = dr["Host_key"].                ToString (); Cc.                ADD (cookie); if (cookie. Name.equals ("_discuz_uid")) uid = cookie.            Value; } cookies.            Cookiecollection = CC; Rq.            cookies = cookies; Rq.            IsPost = true; Rq.            Encoding = Encoding.default; Rq. URL = string.            Format (@ "http://emuch.net/bbs/memcp.php?action=getcredit&uid={0}", UID); RP = http. Excute (RQ);
Let's take a look at the victories:



Yes, the interface is so cool! The interface takes the left, middle, and right classic layouts, with the intention of making you want to vomit when you see it. Among them, the left interface is useful, the middle and the right is used for debugging.

This article is about to end, the HTTP request tool class is online, the great God, not live, directly used.

In the future can be happy to rob Gold.

Finish.


By the same means, the cookie for the default website login is stored locally, isn't it? So, to grab the coins in the right position, you have to have a successful login with the Chrome browser.

Finish.




C # Auto-collect gold function to a website

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.