如何在不键入的情况下发送用户名和密码?

I want to create an Application (C++) for my schoolmates.

Normally they have to go to our school-website and get to the login site. There, they type their username and password, login and search for their own class.

I want my application to ask them for class, username and password, send it to the timetable site, download the url and print the timetable for them.

I'm only programming C++ so I don't have a problem with all that except the "sending username and password to the site" step. I know the HTML basics so I think i have to search for the variable names used by the site and send them together with the url somehow? I tried some things but I don't understand how that whole thing works.

<label id="username-lbl" for="username" class="required" aria-invalid="false">
"Benutzername"
<span class="star">&nbsp;*</span></label>
<input type="text" name="username" id="username" value class="validate-username required" size="25" required aria-required="true" autofocus>

This is the HTML of the Username field. Do i have to write like

...URL....\index.html&username="theusername" because the id is "username" ? I tried this and it didnt work .. i searched alot on the internet but i dont find an answer.

Before going any further, check the <form> element's method. The way submitted data is sent changes.

  • If method is GET (or missing), then submitted data is indeed appended to the URL. It is separated from the rest of the URL (as specified by the action attribute) using ? and name-value pairs are separated by &. You also need to properly URL-encode the values.

  • If method is POST, then data is send in the body of the request. The format depends on the enctype.

Note that there is also the possibility that the data is actually sent using XHR (aka Ajax aka XMLHttpRequest).

The easiest way to get a feel of how things work is to open the Network tab of the Development tools of your favorite browser. It'll tell you whether it's a regular page or XHR, POST or GET, etc.

Note that in many cases, the server will then set cookies to keep state, so you'll have to do the same on your side.

So your C++ program should collect params required and generate valid HTTP POST request.

First you should inspect how that POST request looks like. One of possible ways to do so is using browser developer tools, network tab:

enter image description here

Inspect all headers and bodies. See how these things work and try to make hardcoded request and send it from your C++ program using some HTTP library.

It might authenticate your user and return token or other value that you might use to authenticate requests from your program, and then for other requests include these headers so you can act as a user and fetch user content.

This also depends on authentication implementation, some strategies allow you to do so while some are protected. But I successfully used this technique on production-steady application. I could send various cURL requests and visit pages from my terminal acting as logged in user without logging in or using browser at all. (I didn't login because I just "stole" session from already logged in (and probably remembered) user). In your case you need to login first to obtain these headers (also using your C++ HTTP lib) and then inject new headers to future requests that fetch data.