I am trying to connect to the wifi in my school using Arduino. I have no problem getting a connection to the wifi, but it's not that simple. After connecting to the wifi, I have to go to a login webpage to submit my username and password in order to get the full access to the Internet. By using Chrome's developer tools, I have known it's actually a POST request. So I used exactly the same POST request headers and body in my code.
Here is my code (some info has been revised for privacy):
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");
}
and the request headers:
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
and form data:
buttonClicked=4&redirect_url=&err_flag=0&username=XXXXXXXXX&password=XXXXXXXX
However, it seems that I miss something because I still didn't get the full access to the Internet. The login server responded me a HTML which redirected me to the original login webpage.
Where did I do wrong?
update
this is the HTML which the server responded:
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>