# Login to a https webserver with username and password

**URL:** <https://forum.arduino.cc/t/login-to-a-https-webserver-with-username-and-password/945419>\
**Category:** Programming\
**Created:** [January 10, 2022, 12:23pm UTC](https://forum.arduino.cc/t/login-to-a-https-webserver-with-username-and-password/945419 "2022-01-10T12:23:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![belva78](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@belva78](https://forum.arduino.cc/u/belva78)\
**Post date:** [January 10, 2022, 12:23pm UTC](https://forum.arduino.cc/t/login-to-a-https-webserver-with-username-and-password/945419/1 "2022-01-10T12:23:09Z")

</div>

Hi everybody, this is my first post, so I hope I'm doing the right moves on the forum !  
I'm quite new about Arduino and I'm working on a "classic" project, but with a issues that I didn't solve.  
I use a Arduino Uno WIFI Rev 2 to connect to a wifi and send data by using POST request to a webserver. I used WifiNINA and ArduinoJSON.  
The problem is: I never entered inside the IF after client.connectSSL, because by using a browser I need to login with username and password in a classic login page...but I don't find working solutions with Arduino.  
The code that I'm using is the following:

```cpp
#include <WiFiNINA.h>
#include <ArduinoJson.h>
#include <SPI.h>

char ssid[] = "XXXXXXXXXXXXXXXXXX";
char pass[] = "XXXXXXXXXXXXXXXXXX";

int status = WL_IDLE_STATUS;
DynamicJsonDocument doc(1024); // 
char server[] = "https://XXXXXXXXXXXXX";

WiFiClient client;

void setup() {

  Serial.begin(9600);

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(5000);
  }

  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  IPAddress gateway = WiFi.gatewayIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  String fv = WiFi.firmwareVersion();
  if (fv != "1.4.8") {Serial.println("Please upgrade the firmware"); }
} // end setup

void loop() {
  
 
  doc["XXXXX"][0] = "XXXXXX";
  doc["XXXX"] = "XXXXX";
  doc["XXXXX"] = "XXXXXX";
  
  Serial.print("Provo a connettermi !...\n\r ");
  if (client.connectSSL(server, 443)) {
	
    Serial.print("Sono connesso !...invio la richiesta POST \n\r ");
    client.println("POST \'https://XXXXXXXXX' ");
   // client.println("Host: https://XXXXXXXX");
    client.println("accept: application/ld+json"); 
    client.println("Content-Type: application/ld+json"); 
    client.println("Connection: close");  
    client.print("Content-Length: 1024");
    client.println(measureJson(doc)); 
    client.println();
    serializeJson(doc, client);
  // client.print(doc);
  }
  else{Serial.print("Non sono connesso \n\r");}

  if (client.connected()) {
    client.stop();
  }
   Serial.print("Risultato...: ");
  Serial.println(serializeJson(doc, client));

  delay(3000);
}

```

Thank you !

---

<div class="post-metadata">

**Author:** ![gpb01](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gpb01/32/830685_2.png) [@gpb01](https://forum.arduino.cc/u/gpb01)\
**Post date:** [January 10, 2022, 12:38pm UTC](https://forum.arduino.cc/t/login-to-a-https-webserver-with-username-and-password/945419/2 "2022-01-10T12:38:53Z")

</div>

Your post was **MOVED** to its current location, from the **ITALIAN** section, as it is more suitable.

Could you also take a few moments to [Learn How To Use The Forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966).

Other general [help and troubleshooting advice can be found here.](https://forum.arduino.cc/t/please-check-the-troubleshooting-guide-before-posting-here/52209/2)

It will help you get the best out of the forum in the future.

Guglielmo

---

<div class="post-metadata">

**Author:** ![belva78](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@belva78](https://forum.arduino.cc/u/belva78)\
**Post date:** [January 10, 2022, 2:13pm UTC](https://forum.arduino.cc/t/login-to-a-https-webserver-with-username-and-password/945419/3 "2022-01-10T14:13:21Z")

</div>

Thank you gpb01 !

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [January 10, 2022, 6:17pm UTC](https://forum.arduino.cc/t/login-to-a-https-webserver-with-username-and-password/945419/4 "2022-01-10T18:17:31Z")

</div>

> [@belva78](#):
>
> ```arduino
> client.print("Content-Length: 1024");
> client.println(measureJson(doc)); 
> 
> ```

I think you will need to remove the "1024".

> [@belva78](#):
>
> ```arduino
> if (client.connected()) {
> client.stop();
> }
> Serial.print("Risultato...: ");
> Serial.println(serializeJson(doc, client));
> 
> ```

You may need to send the data to the client before you stop it.

---

<div class="post-metadata">

**Author:** ![belva78](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@belva78](https://forum.arduino.cc/u/belva78)\
**Post date:** [January 12, 2022, 11:25pm UTC](https://forum.arduino.cc/t/login-to-a-https-webserver-with-username-and-password/945419/5 "2022-01-12T23:25:56Z")

</div>

Thank you very much johnwasser and I agree, but the main problem is that I don't reach the server under https !  
I've tried even with ArduinoHttpClient library, but the best case is to receive a 400 error or a timeout !

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 11, 2022, 11:26pm UTC](https://forum.arduino.cc/t/login-to-a-https-webserver-with-username-and-password/945419/6 "2022-07-11T23:26:37Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
