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

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

问题描述:

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.

我想为同学创建一个应用程序(C ++)。 p>

通常他们必须去我们学校的网站并进入登录网站。 在那里,他们输入用户名和密码,登录并搜索自己的类。 p>

我希望我的应用程序向他们询问课程,用户名和密码,将其发送到时间表网站,下载网址并打印时间表。 p>

我只编写C ++,所以除了“向站点发送用户名和密码”步骤之外,我没有遇到任何问题。 我知道HTML基础知识,所以我认为我必须搜索网站使用的变量名称,并以某种方式将它们与url一起发送? 我尝试了一些东西,但我不明白整个过程是如何工作的。 p>

 &lt; label id =“username-lbl”for =“username”class =“required”  aria-invalid =“false”&gt; 
“Benutzername”
&lt; span class =“star”&gt;&amp; nbsp; *&lt; / span&gt;&lt; / label&gt; 
&lt; input type =“text”name  =“username”id =“username”value class =“validate-username required”size =“25”required aria-required =“true”autofocus&gt; 
  code>  pre> 
 
 

这是用户名字段的HTML。 我是否必须像 p>

... URL .... \ index.html&amp; username =“theusername” code>一样写,因为id是“用户名”? 我试过这个并没有用。我在互联网上搜索了很多,但我找不到答案。 p> div>

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.