我正在尝试使用Arduino连接到我学校的wifi。我没有问题可以连接到wifi,但这不是那么简单。连接到wifi后,我必须进入登录页面以提交我的用户名和密码,才能完全访问Internet。通过使用Chrome的开发人员工具,我知道它实际上是一个POST请求。因此,我在代码中使用了完全相同的POST请求标头和正文。
这是我的代码(出于隐私目的对某些信息进行了修改):
if (client.connect(server, 80)) {
Serial.println("connected to server");
client.println("POST /login.html HTTP/1.1");
client.println("Host: wlan.XXXX.edu.tw");
client.println("Connection: keep-alive");
client.println("Content-Length: 77");
client.println("Cache-Control: max-age=0");
client.println("Origin: https://wlan.XXXX.edu.tw");
client.println("Upgrade-Insecure-Requests: 1");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36");
client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
client.println("Referer: https://wlan.XXXX.edu.tw/fs/customwebauth/login-XXXX.html?switch_url=https://wlan.XXXX.edu.tw/login.html&ap_mac=00:d7:XX:XX:XX:XX&wlan=XXXX-WLAN&statusCode=1");
client.println("Accept-Encoding: gzip, deflate, br");
client.println("Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7");
client.println("Cookie: _ga=GA1.3.155XXXXXXX.154XXXXXXX");
client.println("");
client.print("buttonClicked=4&redirect_url=&err_flag=0&username=XXXXXXXXX&password=XXXXXXXX");
}
和请求标头:
POST /login.html HTTP/1.1
Host: wlan.XXXX.edu.tw
Connection: keep-alive
Content-Length: 77
Cache-Control: max-age=0
Origin: https://wlan.XXXX.edu.tw
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: https://wlan.XXXX.edu.tw/fs/customwebauth/login-XXXX.html?switch_url=https://wlan.XXXX.edu.tw/login.html&ap_mac=00:d7:XX:XX:XX:XX&wlan=XXXX-WLAN&statusCode=1
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: _ga=GA1.3.155XXXXXXX.154XXXXXXX
和表格数据:
buttonClicked=4&redirect_url=&err_flag=0&username=XXXXXXXXX&password=XXXXXXXX
但是,似乎我错过了一些东西,因为我仍然无法完全访问Internet。登录服务器回复了我一个HTML,该HTML将我重定向到了原始登录网页。
我在哪里做错了?
更新
这是服务器响应的HTML:
HTTP/1.1 200 OK
Server: HTTP Appgw
Content-Type: text/html
Content-Length: 325
<HTML>
<HEAD>
<TITLE> Web Authentication Redirect</TITLE>
<META http-equiv="Cache-control" content="no-cache">
<META http-equiv="Pragma" content="no-cache">
<META http-equiv="Expires" content="-1">
<META http-equiv="refresh"
content="1; URL=https://wlan.XXXX.edu.tw/login.html?redirect=wlan.XXXX.edu.tw/login.html">
</HEAD>
</HTML>