Using C # to simulate the use of office network login--httpclient

Source: Internet
Author: User

What we're going to do today is use C # to develop a desktop application that can log into the office and take personal information

There are mainly httpclinet and regular expressions.

Direct

is the interface of the program, enter the correct account password and enter the wrong account password interface

Put the code below.

private void Button1_Click (object sender, EventArgs e)        {            HttpClient client = new HttpClient ();            var login = client. Getstringasync ("http://e.tju.edu.cn/Main/logon.do?uid=" +username. text+ "&password=" +password. Text). Result;            string reg = "Current User: ([^<]*) &nbs";            Regex r = new Regex (reg);            MatchCollection res = r.matches (login);            if (res. Count = = 0)            {                MessageBox.Show ("Login Failed");            }            else            {                MessageBox.Show (res[0]. GROUPS[1]. ToString (). Replace ("", "") + "login Successful");            }        }

First we instantiate the HttpClient

Then call the Getstringasync method to indulge GET request, here does not use the Post method, because found that the office network can actually accept post and get two methods of submission, get method is simpler, directly splicing URL can

Then you use regular expressions to match

Current User: ([^<]*) &nbs
This content is meant to match all the content between the current user and the &nbs
Then the result of going out to judge, if there is no content, it will be judged as login failure, otherwise the content formatted output

This time it's easier, but it can be used in many places.

Using C # to simulate the use of office network login--httpclient

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.