0

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>
  • I think you have to first do GET request to this site, accept cookies and then do POST with correct cookies. – Matej Feb 20 '19 at 10:42
  • @Matej, what do you mean "accept cookies"? Also, does Arduino has the ability to accept cookies? Sorry I'm new to this and have no idea. – kevincgreen Feb 20 '19 at 12:18
  • this thing `_ga=GA1.3.155XXXXXXX.154XXXXXXX`, this cookie is not everytime same, right? – Matej Feb 20 '19 at 12:20
  • No. It doesn't change. Should it? – kevincgreen Feb 20 '19 at 12:26
  • I think it's for identifying client. Is there any text in redirect after login? – Matej Feb 20 '19 at 14:34
  • @Matej I add it to the post! – kevincgreen Feb 20 '19 at 15:06
  • There is nothing important in this message. I would try to get `Set-Cookie` header like in this link: https://techtutorialsx.com/2018/06/08/esp8266-arduino-getting-http-response-headers/ and then use it in `client.println("Cookie:` – Matej Feb 20 '19 at 15:47

0 Answers0