简体   繁体   English

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

[英]How can you send Username and Password without typing it?

I want to create an Application (C++) for my schoolmates. 我想为我的同学创建一个应用程序(C ++)。

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. 我只编写C ++,所以除了“向站点发送用户名和密码”步骤之外,我没有遇到任何问题。 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? 我知道HTML基础知识,所以我认为我必须搜索网站使用的变量名称,并以某种方式将它们与url一起发送? 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. 这是用户名字段的HTML。 Do i have to write like 我必须写得像

...URL....\\index.html&username="theusername" because the id is "username" ? ...URL....\\index.html&username="theusername"因为id是“用户名”? 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 . 在继续之前,请检查<form>元素的method The way submitted data is sent changes. 提交数据的方式是发送更改。

  • If method is GET (or missing), then submitted data is indeed appended to the URL. 如果methodGET (或缺失),则提交的数据确实附加到URL。 It is separated from the rest of the URL (as specified by the action attribute) using ? 它与URL的其余部分(由action属性指定)分开使用? and name-value pairs are separated by & . 和名称 - 值对由&分隔。 You also need to properly URL-encode the values. 您还需要对值进行正确的URL编码。

  • If method is POST , then data is send in the body of the request. 如果methodPOST ,则在请求正文中发送数据。 The format depends on the enctype . 格式取决于enctype

Note that there is also the possibility that the data is actually sent using XHR (aka Ajax aka XMLHttpRequest). 请注意,还有可能使用XHR(也称为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. 它会告诉你它是普通页面还是XHR,POST或GET等。

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. 请注意,在许多情况下,服务器将设置cookie以保持状态,因此您必须在您这边做同样的事情。

So your C++ program should collect params required and generate valid HTTP POST request. 所以你的C ++程序应该收集所需的params并生成有效的HTTP POST请求。

First you should inspect how that POST request looks like. 首先,您应该检查POST请求的样子。 One of possible ways to do so is using browser developer tools, network tab: 其中一种可能的方法是使用浏览器开发人员工具,网络选项卡:

在此输入图像描述

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. 了解这些内容是如何工作的,并尝试使用某些HTTP库从您的C ++程序发出硬编码请求。

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. 我可以发送各种cURL请求,并从我的终端访问作为登录用户的页面,而无需登录或使用浏览器。 (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. 在您的情况下,您需要首先登录以获取这些标头(也使用您的C ++ HTTP库),然后为将来获取数据的请求注入新标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM