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